2

如何在 TinyXML 中解析以下内容:

<multi_path literal="not_measured"/>

我能够轻松解析以下行:

<hello>1234</hello>

问题是第一个语句没有被正常解析。请建议如何去做。

4

1 回答 1

2

不是 100% 确定你的问题在问什么,但这是一种基本格式,也可以使用 tinyXML 循环遍历 XML 文件:

/*XML format typically goes like this:
<Value atribute = 'attributeName' >
Text
</value>
*/
TiXmlDocument doc("document.xml");
bool loadOkay = doc.LoadFile(); // Error checking in case file is missing
if(loadOkay)
{
    TiXmlElement *pRoot = doc.RootElement();
    TiXmlElement *element = pRoot->FirstChildElement();
    while(element)
    {
        string value = firstChild->Value(); //Gets the Value
        string attribute = firstChild->Attribute("attribute"); //Gets the attribute
        string text = firstChild->GetText(); //Gets the text
        element = element->NextSiblingElement();
    }
}
else
{
    //Error conditions
} 
于 2010-11-14T20:21:46.607 回答