我刚刚开始使用TinyXML2,所以我可能做错了什么。总之:
tinyxml2::XMLDocument txDoc;
tinyxml2::XMLElement *rootnode;
XMLError err = txDoc.LoadFile(xmlFile.c_str()); // err says no error.
rootnode = txDoc.FirstChildElement("common");根节点仍然设置为最后一行后的空指针。我想这是因为它找不到“共同的”。
以下是我的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。
我给人的印象是我的文件导航不正确。
发布于 2014-05-18 21:14:23
对于XMLDocument,RootElement()和根元素在这里是font。您希望调用根元素的FirstChildElement()。
https://stackoverflow.com/questions/23726661
复制相似问题