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. Qt Xml QDomDocument Special character handling
Forum Updated to NodeBB v4.3 + New Features

Qt Xml QDomDocument Special character handling

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.8k 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.
  • P Offline
    P Offline
    prady_80
    wrote on last edited by
    #1

    Hi,

    I have QString which contains XML data that is obtained from a remote system.
    The problem with this data is that the special characters are not translated. for example & is not translated to &amp.
    When I try to parse this xml using QDomDocument's setContent method, I experience a failure.

    Does Qt Xml handling any how have the facility of escaping such characters or replacing them with the translated characters so that the Xml document becomes a valid document?

    Any help is greatly appreciated.

    Please note that I cannot change the data format that I am receiving as the remote system is not under my control, so CDATA option is not available.

    Thanks

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      [quote author="prady_80" date="1383747289"]
      I have QString which contains XML data that is obtained from a remote system.
      The problem with this data is that the special characters are not translated. for example & is not translated to &amp.[/quote]
      As you may have noticed translating "&" to "&amp" also contains a "&" ;)

      Thus it's the responsibility of the remote system that all special characters are converted to their entities inside text-nodes.

      QString doesn't do any implicit entity conversations.

      What errors do you get when using QDomDocument::setContent()?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tilsitt
        wrote on last edited by
        #3

        Hi,

        What is the text encoding used by your XML data?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prady_80
          wrote on last edited by
          #4

          Encoding is UTF-8 and "unexpected character" is the error I get.
          The & character is the first one to get translated
          Order of translation should therefore be
          '&' -> "&"
          first and
          anyone after that
          ''' -> "'"
          '"' ->"""
          '>' -> ">"
          '<' -> "<";

          1 Reply Last reply
          0
          • P Offline
            P Offline
            prady_80
            wrote on last edited by
            #5

            I have finally a solution that I don't like much.
            Posting it for any further comments.
            I use QXmlStreamReader to read the document and allow it to fail.
            I get the point of failure using characterOffset() . Using this offset peak into the buffer... if the error is correctable... correct it else report a failure.
            If corrected then re-parse to check validity ...do this till everything is correct or a true error happens.

            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