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. [SOLVED] QXmlDomDocument parsing fails to read processing instruction
Forum Update on Monday, May 27th 2025

[SOLVED] QXmlDomDocument parsing fails to read processing instruction

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.0k 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.
  • I Offline
    I Offline
    izzy.coding
    wrote on 19 Aug 2014, 09:09 last edited by
    #1

    I am trying to read an xml string which is loaded from a file and I am getting an invalid character in the processing instruction. Why is this happening?

    My xml is:
    @
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <item id="item1">item1 description</item>
    <item id="item2">item2 description</item>
    <item id="item3">item3 description</item>
    </root>
    @

    This is my function:
    @
    void readXml(QIODevice* device)
    {
    int line, col;
    QString msg;
    QDomDocument doc;
    if (doc.setContent(device, &msg, &line, &col))
    {
    qDebug() << "Success";
    }
    else
    {
    qDebug() << QString("%1\n%2\n%3").args(msg, QString::number(line), QString::number(col)));
    }
    }
    @

    Is there something I am doing wrong here? I need to be able to read this xml string. I cannot change it as this is comming from an external source.

    Any help would be greatly appreciated.

    Every line of code is an error waiting to happen

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JohanSolo
      wrote on 19 Aug 2014, 09:12 last edited by JohanSolo
      #2

      If the snippet you provided is exactly what you 're using, then line 6 is wrong: setContent expects a pointer on a QIODevice, you're providing a QIODevice**...

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        izzy.coding
        wrote on 19 Aug 2014, 09:21 last edited by
        #3

        @Johan: Sorry that was a typo. I have updated the post with corrected parameter.

        I have had to simplify my example as I cannot use the real code on here due to NDA. I am just confused why the QDomDocument does not seem to be able to handle the quotes in the processing instruction of the xml.

        Every line of code is an error waiting to happen

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JohanSolo
          wrote on 19 Aug 2014, 09:36 last edited by JohanSolo 5 Nov 2015, 07:14
          #4

          I am just confused why the QDomDocument does not seem to be able to handle the quotes in the processing instruction of the xml.

          Well, it definitly does handle this, I use it every day. Could you give us information on the Qt version and platform you're using?

          Another thing may be the XML document itself: it is is using an exotic encoding for the quotes, and then claims it is UTF-8... just a wild shot.

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

          1 Reply Last reply
          0
          • I Offline
            I Offline
            izzy.coding
            wrote on 19 Aug 2014, 09:54 last edited by
            #5

            I am using QtCreator 3.1.2 with Qt 5.3.1 on a Mac OSX pc running the latest OS with all patches. I am compiling with the C++11 compiler flags. I am editing the xml file in QtCreator as a resource file so dont think the quotes would be anything outher than the normal double quotes.

            Every line of code is an error waiting to happen

            1 Reply Last reply
            0
            • I Offline
              I Offline
              izzy.coding
              wrote on 19 Aug 2014, 11:11 last edited by
              #6

              Hey,

              I have figured out what my problem was. I have got code that checks if a custom config file exists and if not copies the resource one to disk. However the first time I ran this it put a broken xml file. The broken xml file had " instead of just " as it was copied from code originally. Now because the file existed it was not using my updated version. I have now resolved it and my execution now works as expected.

              Every line of code is an error waiting to happen

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JohanSolo
                wrote on 19 Aug 2014, 11:16 last edited by
                #7

                OK I'm glad you solved your problem.

                Please edit the title and prepend [SOLVED] so that reader know this issue is closed.

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

                1 Reply Last reply
                0

                1/7

                19 Aug 2014, 09:09

                • Login

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