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. XML parsing help
Forum Updated to NodeBB v4.3 + New Features

XML parsing help

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.2k Views 1 Watching
  • 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
    maybnxtseasn
    wrote on last edited by
    #1

    Could anyone provide me a short example of how i can use QT to parse the following XML information which is stored inside a QString variable
    @
    <ErrorMessage>
    <Title>title</Title>
    <Message>messageeeeeeeeee</Message>
    </ErrorMessage>
    @

    When the <ErrorMessage> is reached...i would like to parse Title and Mesage text contents into 2 QString variables.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Take a look at [[doc:QXmlStreamReader]] and in particular the constructor that takes a QString as an argument.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maybnxtseasn
        wrote on last edited by
        #3

        The following is returning a blank string when i try to read the text inside the tags...code and example of text bolded that im wanting to copy

        @
        <ErrorMessage> <Title>title</Title> <Message>messageeeeeeeeee</Message>
        </ErrorMessage>
        @

        @Error ParseError(QXmlStreamReader& streamReader)
        {
        Error temp;
        streamReader.readNext();
        while (!(streamReader.tokenType() == QXmlStreamReader::EndElement && streamReader.name() == "ErrorMessage")) {
        if (streamReader.tokenType() == QXmlStreamReader::StartElement) {

        if (streamReader.name() == "Title") {
        temp.strTitle = streamReader.text().toString();
        }
        if (streamReader.name() == "Message") {
        temp.strMessage = streamReader.text().toString();
        }
        }
        streamReader.readNext();
        }
        return temp;
        }@

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          Well, I don't see any obvious mistake in your snippet.
          Why don't you try to put some qDebug() statements here and there to see the name of the nodes you are processing? It would allow to check that your QXmlStreamReader object is correctly initialised and in a good state.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Set a breakpoint early in that procedure, and step through the code in your debugger. That will guide you to your issue. You can inspect every variable along the way.

            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