Results 1 to 4 of 4

Thread: QDom & xhtml

  1. #1
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QDom & xhtml

    Hi,

    This is my first experience with both DOM and xml. My aim is to use QDom to parse xhtml data.
    I do not understand why the QDomNodeList contains 0 elements (according to gdb).

    Qt Code:
    1. <html>
    2. <body>
    3. <p>
    4. <report id="1">dd:</report>
    5. </p>
    6. <p>
    7. <report id="2">MM:</report>
    8. </p>
    9. <p>
    10. <report id="3">yyyy:</report>
    11. </p>
    12. </body>
    13. </html>
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QFile file("template.xhtml");
    2. if (!file.open(QIODevice::ReadOnly))
    3. return;
    4. if (!doc.setContent(&file)) {
    5. file.close();
    6. return;
    7. }
    8. file.close();
    9.  
    10. QDomNodeList nodeList = doc.elementsByTagName("report");
    To copy to clipboard, switch view to plain text mode 

    How can I populate such list ?
    any clue ?

    thanks in advance

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDom & xhtml

    I've worked with a Dom XML structure in my software and it looks to be the same. I am using Python so my answer might be incorrect, but I think you need to find the root of the document. I'll show you a snippet of code.
    Qt Code:
    1. tree = xml.parseXml(txt)._get_documentElement()
    2. ini.close()
    3. node_list = tree.getElementsByTagName("MetaServerBaseURL")
    To copy to clipboard, switch view to plain text mode 
    Like I said, it's python, not pure Qt, but it definitely looks similar.

    I should mention I don't like the DOM. Python has Element Tree and that is a much cleaner and more efficient way of finding data in XML files. I am a Qt Newbie, so I don't know if they have something like that in the language. If they do I would recommend moving away from the DOM.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDom & xhtml

    Quote Originally Posted by Potch View Post
    I do not understand why the QDomNodeList contains 0 elements (according to gdb).
    Then you a) don't understand how to use gdb correctly or b) you open the wrong file.
    Qt Code:
    1. QString str = "<html><body><p><report id=\"1\">dd:</report></p>"
    2. "<p><report id=\"2\">MM:</report></p>"
    3. "<p><report id=\"3\">yyyy:</report></p></body></html>";
    4. doc.setContent(str);
    5. QDomNodeList nodeList = doc.elementsByTagName("report");
    6. qWarning() << nodeList.count(); // returns 3
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Lykurg for this useful post:

    Potch (19th February 2010)

  5. #4
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDom & xhtml

    Ok for a)
    : /

    THanks !

Similar Threads

  1. XML editing with QDom
    By trulysachin in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2008, 16:39
  2. xhtml/css text formatting
    By kernel_panic in forum Qt Programming
    Replies: 10
    Last Post: 30th October 2007, 14:21
  3. QDom
    By mickey in forum General Programming
    Replies: 9
    Last Post: 17th September 2007, 16:12
  4. parsing using QDOM
    By aruna in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2007, 12:46
  5. A sample XSLT transformation from Qt rich text to XHTML
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2006, 17:23

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.