Skip to content
  • 0 Votes
    3 Posts
    1k Views
    P

    Hi,
    Creating a very "abstract" xml parser is not easy and it's quite error-prone. You have to know some (or at least one) parent or common tag names in order to have a starting point for any deeper "abstract" parsing. Basically, you have to move the parser step by step checking everything in the way. For example, you could use a simple function as an entry point for the following function when you meet a specific tag:

    void XmlReader::readFragment() { Q_ASSERT(m_reader->isStartElement()); //Make sure the xmlreader is at an opening tag const QString p = m_reader->qualifiedName().toString(); // From now on, you will work with this opening tag //Do what you want, for example handle attributes and their values for (auto i = 0; i < m_reader->attributes().count(); ++i) { ... } m_reader->readNext(); //Move on ... //Do everything manually like this if (m_reader->isCharacters) { ... } else if (m_reader->isEndElement()) { ... } //or like this //Eventually, you have to check for the closing current tag, exit the function, //and return the control to the "entry point" function while (!m_reader->isEndElement() && !m_reader->qualifiedName().toString() == p) { ... //Do your work m_reader->readNext(); } }

    However, with this approach, things can get extremely complicated if there are nested tags, for example:

    <p> <note> <p>...</p> </note> </p>

    Maybe it would be easier to subclass QXmlStreamReader but it would help to provide some sample xml data and more info on what exactly you want to do.

  • 0 Votes
    3 Posts
    852 Views
    CharlieGC

    Hi,

    Too bad... :( :( :( :( ... but I think that : everything is possible with Qt & QML !!!! And I am right :

    XmlListModel { id: xmlModel source: "data.xml" query: "/root/element[@type='type1']"

    This solution allow to get only the element with type = type1.... Yoouuuupiiiiii ;-)

    Cooollll