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.
find child element with rapid xml
Pergunta
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.
Solução