0

I try to get the child element of an simple xml but it does not work correct. I get Runtime exception: Access violation reading location 0x0000000. I simply try to access it like this:

Config::Config()
{
    rapidxml::file<> xmlFile("config.xml"); 
    rapidxml::xml_document<> m_doc;
    m_doc.parse<0>(xmlFile.data());
    LOG(m_doc.first_node()->name());//simple cout makro
    LOG(findNode("test")->value()); 
}

xml_node<>* Config::findNode(const char* name)
{
    LOG("looking for "<< name);
    return m_doc.first_node()->first_node(name);
}

The xml is simple:

<root>
    <test>test</test>
</root>

I do get the log for the root element from the line LOG(m_doc.first_node()->name()); and the log from the "looking for". I have no clue what i am doing wrong? I get the first element which should be root (and logger say so) and than i try to find the first child with the name test. Which should have the value test. I also get the same exception if i try to print the name or such.


UPDATE: I just tried LOG(m_doc.first_node()->first_node("test")->value());and this does return the correct value. But i cant call my method to do this. What have i done wrong with the method? Any clue? LOG(findNode("test")->value()); does not work . So something isn't right with it.

bemeyer
  • 6,154
  • 4
  • 36
  • 86

1 Answers1

1

You've (re)declared m_doc as a local variable in Config::Config, shadowing what is presumably a member variable. Just get rid of that declaration.

ooga
  • 15,423
  • 2
  • 20
  • 21
  • i am totaly confused. I just tried `LOG(m_doc.first_node()->first_node("test")->value());`and this does return the correct value. But i cant call my method to do this. What have i done wrong with the method? Any clue? `LOG(findNode("test")->value());` does not work – bemeyer Apr 16 '14 at 18:09
  • 1
    @BennX I think I've spotted your error. See updated answer above. – ooga Apr 16 '14 at 18:15
  • yea right... cpp is still new to me and i always forget not to declare it again if its in the header file. Thanks alot! – bemeyer Apr 16 '14 at 18:16