XMLファイルがあります(単純化する必要がありました):
<Line line1_attr1 = "value1" line1_attr2 = "value2">
<Term line1_term1_attr1 = "term1value1" line1_term1_attr2 = "term1value2">
term content
</Term>
<Term line1_term2_attr1 = "term2value1" line1_term2_attr2 = "term2value2">
term content
</Term>
</Line>
<Line line2_attr1 = "value1" line2_attr2 = "value2">
<Term line2_term1_attr1 = "term1value1" line2_term1_attr2 = "term1value2">
term content
</Term>
<Term line2_term2_attr1 = "term2value1" line2_term2_attr2 = "term2value2">
term content
</Term>
</Line>
mapString
属性は、( Line の属性) とMapTerm
(Term の属性)の 2 つの QMap に格納されます。タグの属性は読み取れますが、Line
タグの属性は読み取れませんTerm
。これも
if(token == QXmlStreamReader::StartElement)
{
if (xml.name() == "Line")
{
QXmlStreamAttributes attrib = xml.attributes();
for(auto e : mapString->keys())
{
mapString->insert(e, attrib.value(e).toString());
}
continue;
if (xml.name() == "Term")
{
QXmlStreamAttributes attrib = xml.attributes();
for(auto e : mapTerm->keys())
{
mapTerm->insert(e, attrib.value(e).toString());
}
continue;
}
}
または
if(token == QXmlStreamReader::StartElement)
{
if (xml.name() == "Line")
{
QXmlStreamAttributes attrib = xml.attributes();
for(auto e : mapString->keys())
{
mapString->insert(e, attrib.value(e).toString());
}
continue;
}
if (xml.name() == "Term")
{
QXmlStreamAttributes attrib = xml.attributes();
for(auto e : mapTerm->keys())
{
mapTerm->insert(e, attrib.value(e).toString());
}
continue;
}
if (xml.name() == "Term")内のコードは実行されません。