Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Iterate over XML with QXmlStreamReader
QtWS25 Last Chance

Iterate over XML with QXmlStreamReader

Scheduled Pinned Locked Moved General and Desktop
xml parsingqxmlstreamreadexml
3 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moravas
    wrote on 9 Sept 2015, 19:30 last edited by
    #1

    Hi Folks,

    I have to build a project that process XML files, so I started to learn a bit about Qt XML with QXmlStreamReader, but it seems I'm in trouble. I have a XML files, like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project>
    <root name="readername">
    <proeprty name="hwInputNumber" ...>
    <proeprty name="defaultGateway" ...>
    <enumeration name="input">
    <proeprty name="trigger" ...>
    </enumeration>
    <enumeration name="output">
    <proeprty name="adress" ...>
    </enumeration>
    </root>
    </project>

    and I wrote some code, that targets to print out the name of the XML nodes and the value of the "name" attribute:
    @
    QXmlStreamReader reader(&_project);
    while (!reader.isEndDocument()) {
    reader.readNextStartElement();
    qDebug() << reader.name() << reader.attributes().value("name");
    reader.skipCurrentElement();
    else if(reader.isEndElement()) {
    reader.readNextStartElement();
    qDebug() << "";
    }
    }
    @

    It seems that the processing getting into an infinite loop when it reaches the "<proeprty name="trigger" ...>" line under the "enumeration" node.

    I guessed that some "step back" should be exist that navigate me to the parent node, but I didn't found such a method in the API reference.

    Can anybody help me?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Sept 2015, 19:51 last edited by
      #2

      Hi,

      You should take a look at the Stream Bookmarks example You'll see how to parse an an xml file.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moravas
        wrote on 11 Sept 2015, 05:13 last edited by
        #3

        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

        1 Reply Last reply
        0

        1/3

        9 Sept 2015, 19:30

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved