使用 TinyXML 查找特定的文本值

Find Specific Text Values With TinyXML

本文关键字:文本 TinyXML 查找 使用      更新时间:2023-10-16

我有如下所示的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=""
}
  1. 打开TiXmlDocument;
  2. 获取根TiXmlElement;
  3. 获取名为"文本"的FirstChild();
  4. 获取名为"value"的Attribute()的值,用它做一些事情;
  5. 获取名为"text"的NextSibling()元素;
  6. 重复直到没有更多的兄弟姐妹。