使用 QT 进行 XML 解析
XML parsing with QT
当我们尝试使用 QT 解析 xml 文档时,我们使用如下内容:
QString str;
QXmlStreamAttributes attrib = xml_reader.attributes();
if(attrib.hasAttribute("id"))
{
str = attrib.value("id").toString();
}
为此,我需要知道该属性称为"id"。有没有办法在不知道其名称的情况下读取第一个属性?
提前谢谢。
QXmlStreamAttributes 类继承自 QVector<QXmlStreamAttribute>
.这意味着您可以像使用 QVector 一样"循环"对象
您应该能够访问第一项:
attrib[0].name(); //containst a QStringRef to the name
attrib[0].value(); //containst a QStringRef to the value
顺便说一下,强烈建议您先检查QVector大小;)
attrib.size(); //contains the number of attributes
相关文章:
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 使用 libxml2 解析 XML 文件时缺少元素值
- 如何解析 xml 响应?
- 如何通过不同的编程语言发送,接收和解析XML消息
- 在 qt 中解析 XML 并获取树标记结构
- 使用 qtxml C++ 解析 XML 文件
- 使用 TinyXML 解析 XML 元素 - 无限循环
- 解析 XML 时出错:标记 XOSP 不匹配
- 解析 xml 到对象,打印标签 - QT 之间的内容
- 解析XML文档
- 解析 xml 并在每个<>块中转储文件
- 用libxml2解析XML文件的最快方法
- 使用 c++ 和 Qt 解析 xml 文件
- 如何在 C++ 中解析 XML 字符串中的数据
- 如何使用提升解析 XML 中的 2 个以上级别
- 从我的c++应用程序调用c#dll(解析XML文件),将数组/列表返回给c++
- 无法在 c++ 中在安卓上加载和解析 xml 文件
- 我正在使用 Xercesc 来解析 xml 文档。我想知道我将如何使用 XML 值作为程序的输入?
- 如何在C++中解析 XML 网页
- 使用 C++ 解析 XML 文件