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. [NEWBIE] simple XML reader - displaying text between tags.
QtWS25 Last Chance

[NEWBIE] simple XML reader - displaying text between tags.

Scheduled Pinned Locked Moved General and Desktop
xml parsing
4 Posts 3 Posters 2.5k 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.
  • G Offline
    G Offline
    Godfreyho
    wrote on last edited by
    #1

    Hello all,

    I'm a newbie here, as well as in the QT environment. I do have some very basic understanding of C++ (procedural, not object-oriented, unfortunately).
    What I'm currently struggling with is a simple XML parser. Basing on the literature and online tutorials I managed to cobble together "something" that works, partially. The problem is, it does not work precisely as intended :-) Here's the code snippet:

    http://pastebin.com/tmwAetZR

    and here's the program's output:

    http://i62.tinypic.com/wtao9k.jpg

    What it does is reading the root and child nodes, but without parsing any text between them (Tove, Jani etc.). I would like to display both the node names and the text between them. I suspect I should put a "QXmlStreamReader" below the "else" if I want to display the text for child nodes, but to be honest - I suck at figuring out what exactly should be put in there.

    Thanks in advance for your help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Did you saw the XML Bookmarks example ? It looks like it does what you need

      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
      • G Offline
        G Offline
        Godfreyho
        wrote on last edited by
        #3

        Thanks for the tip, SGaist!

        I read up on it yesterday and compared the info with what I was able to write before. So what I did was reading another tutorial and adding the:

                    if(name == "to" || name =="from"){
                    string = xmlReader.readElementText();
                    sl << string;"
        

        before the else sl<<xmlReader.name

        It works, i.e. shows the text content between "from" and"to" XML tags. But that procedure above can get very tedious if you have ~40 different XML tags.

        What I was wondering was, is there any 'automagic' function that could read the text between the XML tags?
        That pastebin snippet is able to find XML tags and build a tree basing on tags found inside the file (not really looking for a specific text like "to" or "from") - so would it be possible to use another function that would just search for anything that is between the tags - and display that in the tree as well?

        Sorry if I express myself incorrectly, as I said - I still have a lot to learn.

        Thanks in advance for your help.

        1 Reply Last reply
        0
        • sneubertS Offline
          sneubertS Offline
          sneubert
          wrote on last edited by
          #4

          Hi Godfreyho,

          I don´t know if this is to take a sledgehammer to crack a nut for your
          intend, but if you want XML files to be parsed and output you can
          use a XSLT file with a xsl processor.

          1 Reply Last reply
          0

          • Login

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