Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QXmlDomDocument parsing fails to read processing instruction
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] QXmlDomDocument parsing fails to read processing instruction

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 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.

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on 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
      • ? Offline
        ? Offline
        A Former User
        wrote on 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.

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by JohanSolo
          #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
          • ? Offline
            ? Offline
            A Former User
            wrote on 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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 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.

              1 Reply Last reply
              0
              • JohanSoloJ Offline
                JohanSoloJ Offline
                JohanSolo
                wrote on 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

                • Login

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