I'm sorry but you must be moving the cursor in some way. Try putting Q_ASSERT(m_node.isStartElement()); just before auto x = m_node.attributes().size();
This example parses the XSD you provided correctly (I also let QXmlStreamReader handle namespaces instead of having to write custom code for it):
int main()
{
const QString xmlText(R"***(<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name = "elementName">
<xs:simpleType>
<xs:restriction base = "xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>)***"
);
QXmlStreamReader reader(xmlText);
while (!reader.atEnd()) {
switch(reader.readNext()){
case QXmlStreamReader::StartDocument:
qDebug("Start of document");
break;
case QXmlStreamReader::EndDocument:
qDebug("End of document");
break;
case QXmlStreamReader::StartElement:{
qDebug() << "Started Element: " << reader.name();
const auto attr = reader.attributes();
qDebug() << "Number of Attributes: " << attr.size() << " Attributes:";
for(auto&& att : attr)
qDebug() << att.name() << " = " << att.value();
}
break;
case QXmlStreamReader::EndElement:
qDebug() << "Finished Element: " << reader.name();
break;
default:
break;
}
}
return 0;
}
@jsulm Thank you so much! I modified the implementation based on your suggestion. And the error was resolved.
For anyone landing at this question in the forum, Qt examples directory has a lot of examples for similar cases. I found 'RSS Listing example' (Examples/Qt-5.9.2/xml/rsslisting) to be helpful for my scenario.
Again, it wasn't a suggestion, I was just asking whether you would simply do tag for tag replacement.
Out of curiosity, since you are using doxygen, why not make it generate the html directly ?
Hi and welcome to devnet,
Your path to test.xml is relative so the file should be beside your executable. Currently your executable is located in a shadow build dir. So for your test you can use an absolute path or copy the file in the shadow build dir.
Hi,
thank you very much, it was a really nice help. (Additionally, my XML file wasn't well formatted, but it's fixed).
But there is one thing that I didn't see, how can I relaize: how can I insert a node into an existing XML file?
Regards,
Norbert