使用 c++ & 解析 xml 文件Qt [英] Parse a xml file using c++ & Qt

查看:37
本文介绍了使用 c++ & 解析 xml 文件Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解析具有以下结构的 XML 文件:

I try to parse a XML-file with the following structure:

<I>
  <C c="test1">
     <H><Pd pd="123"/>
        <f p="789" r="456"/>
     </H>
     <M m="test2">
       <H><Pd pd="3456"/><R r="678"/>
       </H>
     </M>
  </C>
  <T t="0">
     <T2>123</T2>
     <T3>2345</T3>
  </T>
  <T t="1">
     <T1>23456</T1>
     <T2>23</T2>
     <T3>123</T3>
     <T4>456</T4>
  </T>
</I>

我有一个数字列表,例如0 和 1 以及搜索模式,例如'23'现在我想用 t="a number from my list" 在 XML 文件中搜索所有 T 节点,其中一个子节点(T1、T2、T3)包含搜索模式.

I have a List of numbers e.g. 0 and 1 and a search pattern e.g. '23' Now i want to search the XML-file for all T-nodes with t="a number from my list" where one of the child nodes(T1, T2,T3) contain the search pattern.

谁能帮我解决这个问题?我想使用 Qt 功能,但不知道如何开始.

Can anybody help me getting started with this problem? I want to use the Qt functions but do not really know how to begin.

我对每一个提示都很满意!

I'm happy about every hint!

推荐答案

未经测试,但这是我已经使用 Qt 扫描一个非常简单的 XML 文件的一种方式.也许这可以给你一个提示如何在这里使用它:

Untested, but this is a way I already used Qt to scan in a very simply XML file. Maybe this can give you a hint how to use it here:

QDomElement docElem;
QDomDocument xmldoc;

xmldoc.setContent(YOUR_XML_DATA);
docElem=xmldoc.documentElement();

if (docElem.nodeName().compare("T")==0)
{
    QDomNode node=docElem.firstChild();
    while (!node.isNull())
    {
        quint32 number = node.toElement().attribute("t").toUInt(); //or whatever you want to find here..
        //do something
        node = node.nextSibling();
    }
}

这篇关于使用 c++ &amp; 解析 xml 文件Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆