我在使用 QXmlStreamReader 获取嵌套标签的值时遇到问题。我的xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Class Name="Simple1">
<Property Name="FloatValue" Type="Float">14.45</Property>
<!-- komentarz -->
<Property Name="IntegerValue" Type="Integer">-23049</Property>
<Property Name="UnsignedValue" Type="Unsigned">123</Property>
</Class>
<Class Name="Simple2">
<Property Name="TestEmbed" Type="Embed" SubType="Simple1">
<Property Name="FloatValueEmbed" Type="Float">1.2</Property>
<Property Name="IntegerValueEmbed" Type="Integer">10</Property>
<Property Name="UnsignedValueEmbed" Type="Unsigned">20</Property>
</Property>
<Property Name="FloatValue" Type="Float">55.55</Property>
<Property Name="IntegerValue" Type="Integer">-1111</Property>
<Property Name="UnsignedValue" Type="Unsigned">888</Property>
</Class>
</root>
我只是无法获取位于其他属性内部的标签属性的值:
while (reader.readNextStartElement())
{
qDebug() << "Found tag: " << reader.name() << "text: " << reader.text() << "token: " << reader.tokenString();// THIS PART WORKS WRONG << "tag value: " << reader.readElementText(); //tried IncludeChildElements too
for (auto &attribute : reader.attributes())
{
qDebug() << "attribute name: " << attribute.name() << ", attribute value: " << attribute.value();
}
reader.skipCurrentElement();
}
怎么了?类 Simple1 已正确读取和列出。