0

I am just starting to use TinyXML2 so I am probably doing something wrong. Anyway:

tinyxml2::XMLDocument txDoc;
tinyxml2::XMLElement *rootnode;

XMLError err = txDoc.LoadFile(xmlFile.c_str()); // err says no error.

rootnode = txDoc.FirstChildElement("common");

rootnode is still set to a null pointer after the final line. I assume this is because it cannot find "common".

Here is my XML (shortened):

<?xml version="1.0"?>

<font>

<info outline="0" spacing="1,1" padding="0,0,0,0" aa="1" smooth="1" stretchH="100" unicode="1" charset="" italic="0" bold="0" size="16" face="Arial"/>

<common blueChnl="0" greenChnl="0" redChnl="0" alphaChnl="1" packed="0" pages="1" scaleH="128" scaleW="256" base="13" lineHeight="16"/>

<pages>
<page file="Font_Arial_16_0.png" id="0"/>
</pages>

<chars count="191">
... (removed additional <char>'s)
<char id="32" chnl="15" page="0" xadvance="4" yoffset="0" xoffset="0" height="16" width="1" y="85" x="121"/>
... (removed additional <char>'s)
</chars>

<kernings count="70">
... (removed additional <kerning>'s)
<kerning amount="-1" second="65" first="32"/>
... (removed additional <kerning>'s)
</kernings>

</font>

However, in the XMLDocument txDoc, the charBuffer only contains:

<?xml version="1.0"?>
<font

And apparently nothing more. So I assume it says there is no error because it finds and opens the file, but doesn't seem to get everything that's inside it.

Does anyone have any ideas? I am using TinyXML2, not 1.

I get the impression I am navigating the file incorrectly.

user1539405
  • 111
  • 1
  • 14
  • won't the '-' just be interpreted as a text node? – Richard Hodges May 18 '14 at 21:06
  • I just copied and pasted from the XML html display. Those are just for expanding the nodes, they aren't actual text inside the document. I'll edit them out of the post :) My guess is I have to enter the "font" node before I can enter the "common" node, but I'm not sure? – user1539405 May 18 '14 at 21:09

1 Answers1

2

For the XMLDocument, FirstChildElement() is equivalent to RootElement() and your root element here is font. You want to call FirstChildElement() of the root element.

Leiaz
  • 2,867
  • 2
  • 20
  • 23
  • Yep. Used RootElement() for the rootnode and created an element node to store the child nodes using FirstChildElement() on the rootnode. Cheers! – user1539405 May 18 '14 at 22:41