This might be more of a c++ problem rather than a rapidxml problem, and I'm still learning c++ so sorry if this is a very stupid question.
I am trying to load an XML file within a try block:
rapidxml::xml_document<> doc;
rapidxml::xml_node<>* root_node;
try
{
rapidxml::file<> file((data_folder + "\\application.xml").c_str());
doc.parse<0>(file.data());
root_node = doc.first_node("Application");
std::cout << root_node->first_node("AppMeta");
}
catch (const std::runtime_error& e)
{
// ...
}
This code correctly prints the pointer of the 'AppMeta' node. The problem is when I move the cout
line outside of the block:
rapidxml::xml_document<> doc;
rapidxml::xml_node<>* root_node;
try
{
rapidxml::file<> file((data_folder + "\\application.xml").c_str());
doc.parse<0>(file.data());
root_node = doc.first_node("Application");
}
catch (const std::runtime_error& e)
{
// ...
}
std::cout << root_node->first_node("AppMeta");
I this case, the value that appears on the console is a nullptr (00000000). Why does this happen, and how can I access the XML dom after the try catch block?