c++ - tinyxml 如何在多个 xml 文件时使用它?

标签 c++ ubuntu

我有一个这样的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 }

它只给了我第一个名字。怎么去第二个?

谢谢

最佳答案

使用 NextSiblingNextSiblingElement 获取 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/

相关文章:

ubuntu - 如何在 WSL 2 上安装 Heroku CLI?

c++ - 点或箭头运算符与范围解析运算符的比较,用于访问基础子对象

Python 多处理,在循环中多次使用池在第一次迭代后卡住

php - 如何为 PHP CLI 启用颜色?

android - libz.so.1 : cannot open shared object file

ubuntu - linux更新后如何维护开发环境

c++ - msys2 静态 QT undefined reference 问题

C++ 二维数组用文件中的最后一个元素值填充所有元素

c++ - 未签名的 WINAPI 函数的正确函数指针是什么?

c++ - Lua C API : what's the difference between lua_gettop() and -1?