使用c ++& Qt [英] Parse a xml file using c++ & Qt
问题描述
我尝试解析具有以下结构的XML文件:
<
< C c =test1>
< H>< Pd pd =123/>
< f p =789r =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'
现在我想在XML文件中搜索所有T节点,其中t =我的列表中的数字,其中子节点(T1,T2,T3)包含搜索模式。 / p>
任何人都可以帮我开始使用这个问题吗?我想使用Qt函数,但不知道如何开始。
我对每一个提示感到高兴!
未测试,但这是一个我已经使用Qt扫描一个非常简单的XML文件的方式。也许这可以给你一个提示如何使用它在这里:
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)。 //或任何你想要在这里找到..
//做某事
node = node.nextSibling();
}
}
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>
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.
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!
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 ++& Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!