Skip to content
  • 0 Votes
    4 Posts
    721 Views
    VRoninV

    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; }