我刚刚开始使用TinyXML2,所以我可能做错了。无论如何:
tinyxml2::XMLDocument txDoc;
tinyxml2::XMLElement *rootnode;
XMLError err = txDoc.LoadFile(xmlFile.c_str()); // err says no error.
rootnode = txDoc.FirstChildElement("common");
rootnode仍然在最后一行之后设置为空指针。我认为这是因为它无法找到“常见”。
这是我的XML(缩写):
<?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>
但是,在XMLDocument txDoc中,charBuffer只包含:
<?xml version="1.0"?>
<font
显然没有更多。所以我认为它没有错误,因为它找到并打开文件,但似乎没有得到它内部的所有内容。
有没有人有任何想法?我使用的是TinyXML2,而不是1。
我得到的印象是我错误地浏览了文件。
答案 0 :(得分:2)
对于XMLDocument
,FirstChildElement()
is equivalent to RootElement()
,您的根元素是font
。您想要调用根元素的FirstChildElement()
。