Parse a xml file using c++ amp; Qt(使用 c++ amp; 解析 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++ & 解析 xml 文件Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 c++ & 解析 xml 文件Qt


- C++ 协变模板 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01