Results 1 to 4 of 4

Thread: XML parsing error with QDom and QStreamReader

  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Question XML parsing error with QDom and QStreamReader

    Hello,
    Currently I struggle with parsing some XML data without idea how to solve my problem. What I want to do is to parse text data from one of the elements in XML, everything is working but not as expected.

    XML example:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <textData>
    3. <text>
    4. ...
    5. <des> Sample data with link <a href = ..> and bb code [bbcode], with entities &trade; </des>
    6. </text>
    7. </textData>
    To copy to clipboard, switch view to plain text mode 
    and I expect to get this:
    Qt Code:
    1. Sample data with link <a href = ..> and bb code [bbcode], with entities &trade;
    To copy to clipboard, switch view to plain text mode 

    Using QDom works fine, I can retrieve that text but the problem is that text is parsed. So I don't get <a href ..>.

    When I use QXmlStreamReader approach thing are getting even more frustrating because data stops on first entity occurrence (I'm using polish characters so ... utf-8 don't handle all of them).

    So conclusion that I cam up with is that error occur with text() function and parsing.

    And the question: is there a way to force QDom / QXmlStreamReader to output raw / unformated text? (currently I don't want to use regexp to parse id out, but it seams that's only way)

    Best regards.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML parsing error with QDom and QStreamReader

    First of all utf-8 handles polish characters just fine. Second of all if your xml file is not a valid xml file then, well... don't expect an xml parser to parse it. If you use entities (such as &trade;), they need to be declared first. If you want a verbatim copy of the contents of the tag, wrap the contents into a CDATA section.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Talei (5th March 2011)

  4. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: XML parsing error with QDom and QStreamReader

    Thanks CDATA is what I need.
    BTW. What do you mean that polish characters are handled fine. I always got for ó a "&oacute;", well I guess You mean that this is correct with I also agree.
    BTW. How to declare a entities?
    Last edited by Talei; 5th March 2011 at 19:39.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML parsing error with QDom and QStreamReader

    Quote Originally Posted by Talei View Post
    BTW. What do you mean that polish characters are handled fine. I always got for ó a "&oacute;"
    I mean that utf-8 can handle polish characters very well. This site is utf-8 encoded and these characters are displayed properly: ĄĆĘŁNÃ“ÅšÅ»Å¹Ä…Ä‡Ä Å‚Å„Ã³Å›Å¼Åº

    BTW. How to declare a entities?
    I'm sorry, this is not a site for teaching XML. Google for XML+entity or something like that. You probably need to reference this document (or similar): http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    Talei (5th March 2011)

Similar Threads

  1. Parse xml file using QStreamReader
    By Gary.zhang in forum Qt Programming
    Replies: 0
    Last Post: 10th January 2011, 04:00
  2. qdom xml update
    By RenanBS in forum Newbie
    Replies: 0
    Last Post: 12th October 2010, 21:53
  3. QDom & xhtml
    By Potch in forum Newbie
    Replies: 3
    Last Post: 19th February 2010, 23:41
  4. QDom
    By mickey in forum General Programming
    Replies: 9
    Last Post: 17th September 2007, 16:12
  5. parsing using QDOM
    By aruna in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2007, 12:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.