我有一个这样的xml
<xml http://......>
<value>
<name>me</name>
<age>12</age>
</value>
<value>
<name>kk</name>
<age>1</age>
</value>
</xml>
这个 xml 在一个名为 s 的字符串值中; 我做了:
const char *data =s.c_str();
TiXmlDocument doc;
doc.Parse((const char*)data, 0, TIXML_ENCODING_UTF8);
const std::string m_name;
TiXmlHandle handle(&doc);
TiXmlElement* section;
section = handle.FirstChild("xml").FirstChild("value").FirstChild("name").Element();
if (section) {//code }
它只给了我第一个名字。怎么去第二个?
谢谢
最佳答案
使用 NextSibling
或 NextSiblingElement
获取 DOM 当前子树的同一层次结构中的下一个元素。
所有 sibling 都链接在一起,对最后一个 sibling 调用 NextSibling
将返回 NULL
。假设您有第一个子元素并想在它和它的所有兄弟元素上运行一些代码,它可能看起来像这样:
TiXmlElement* element = ... (first child element)
do {
// process the current element
}
// try to advance to the next sibling, break the loop if there is none.
while((element = element->NextSiblingElement()) != NULL);
关于c++ - tinyxml 如何在多个 xml 文件时使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6521741/