使用 TinyXML 查找特定的文本值
Find Specific Text Values With TinyXML
我有如下所示的XML文件。我想在不同时间查找特定的文本值。如何使用TinyXML访问文本值
-<language>
<text value="Advanced Sensor Controls" parameter="title"/>
<text value="Refresh" parameter="refresh_button"/>
<text value="Show" parameter="button_show"/>
<text value="Hide" parameter="button_hide"/>
<text value="Raw Command" parameter="label_raw_command_title"/>
<text value="Expected RX" parameter="label_raw_command_expected_rx"/>
</language>
借助这样的代码:
TiXmlDocument file( xmlfilename );
TiXmlElement *language = file.FirstChildElement("language");
for(TiXmlElement *text =
language->FirstChildElement(
"text");
text;
text =
language->NextSiblingElement() )
{
text->Attribute("value"); // this returns text in value=""
text->Attribute("parameter"); // this returns text in parameter=""
}
- 打开
TiXmlDocument
; - 获取根
TiXmlElement
; - 获取名为"文本"的
FirstChild()
; - 获取名为"value"的
Attribute()
的值,用它做一些事情; - 获取名为"text"的
NextSibling()
元素; - 重复直到没有更多的兄弟姐妹。
相关文章:
- 文本文件中的单词链表
- 从命令行c++发送文本文件名
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 2D数组来自文本输入,中间有空格
- 如何将内容数组写入文本文件?
- 无法通过空白将文本文件行分隔为矢量
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- C++将文本文件中的数据读取到结构数组中
- 在指针的帮助下,文本文件中单词的频率
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将值从二维数组输出到文本文件
- 如何在c++中从文本文件中逐行读取整数
- 如何创建一个QTableWidgetItem,用长文本右对齐,左边有省略号
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 如何在C++中确定文本文件中的元素是字符还是数字
- 如何根据单词在文本中出现的概率输出单词
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- C++试图读取一个文件并输出到另一个文本文件
- 使用 TinyXML 查找特定的文本值