Tinyxml2 error while parsing a xml file with c++

1.2k Views Asked by At

I'm using tinyxml2 to parse a xml file. While debugging with some prints:

XMLDocument doc;  
doc.LoadFile("../../Demos/config.xml");
std::cout << "file loaded" << std::endl;

XMLNode * pRoot = doc.FirstChild();
std::cout << "first element loadaed" << std::endl;
if (pRoot == nullptr) std::cout << "oops" << std::endl;

I noticed my program would print the last std::cout and then would give segmentation fault error. My problem is I don't get it why the pRoot is null. The xml file I'm giving my program is the following:

<scene>
    <group>
        <translate X="5" Y="0" Z="2" />
        <rotate angle="45" axisX="0" axisY="1" axisZ="0" />
        <models>
            <model file=”sphere.3d” />
        </models>
    </group>
</scene>

Any help would be appreciated.

1

There are 1 best solutions below

5
On

Check the return value of LoadFile. Does LoadFile return XML_SUCCESS? Otherwise the file might not even be loaded. Are you searching in the right folder?