使用QXmlStreamReader读取XML标签内的值
Read value inside XML tag using QXmlStreamReader
我有XML格式
<Value active="false">8.0</Value>
我使用QXmlStreamReader来解析XML。我能够读取标签&;value &;和实际值"8.0",但我无法读取XML的active="false">
部分。
const QString label = xmlReader.name().toString();
xmlReader.readNext();
const QString text = xmlReader.text().toString();
给出了"Value"在label
和"8.0";in text
.
我将代码修改为
const QString label = xmlReader.name().toString();
const QString labelIn = xmlReader.readElementText();
xmlReader.readNext();
const QString text = xmlReader.text().toString();
但是labelIn
返回一个空字符串。我错过什么了吗?
我正在使用Qt 5.3
节点的active="false"
部分称为属性。要获得它的值,您需要使用QXmlStreamReader
类的专用API:
QXmlStreamAttributes attribs = xmlReader->attributes();
QString attr = attribs.value("active").toString();
相关文章:
- Cppcheck生成xml转储文件
- 如何在pugixml中获取节点的内部XML
- 如何使用tinyxml2从XML加载父实体和子实体
- boost xml parsingl将xml的路径作为变量发送
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 增强基于 XML class_id的反序列化
- C 和 C++ 中开关语句的案例标签的常量值,但显示不同的行为
- 如何正确指定 goto 语句的标签?
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- c++ 读取 xml 文件的内容
- 删除 XML 文件中的子节点C++
- 解析 xml 到对象,打印标签 - QT 之间的内容
- C 添加自定义XML标签,用于序列化对向量
- 获取标签的子标签详细信息[BOOST PORPERTY_TREE XML]
- 我的 XML 标签正则表达式不起作用
- C++ Expat XML 标签支持
- 如果要读取随机森林(opencv3.0)的xml文件,则标签类型必须为float
- 使用QXmlStreamReader读取XML标签内的值