Results 1 to 9 of 9

Thread: reading XML node and sub nodes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    371
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    14
    Thanked 18 Times in 17 Posts

    Default reading XML node and sub nodes

    Hi all,

    I need to parse an XML file. When a specific node, is found, I need to get the exact test inside that tag, not only the "xml text".

    Example:
    Qt Code:
    1. <root>
    2. <a>11111</a>
    3. <a><b>test 123</b></a>
    4. </root>
    To copy to clipboard, switch view to plain text mode 

    In this XML I need to be able to get: "1111" and "<b>test 123</b>".

    I am using this code in Qt5:
    Qt Code:
    1. void test1() {
    2. QString rawXML =
    3. "<root>"
    4. " <a>11111</a>"
    5. " <a><b>test 123</b></a>"
    6. "</root>";
    7. QXmlStreamReader xml(rawXML);
    8. QStringRef s;
    9.  
    10. xml.readNextStartElement();
    11. s = xml.name();
    12. if (s!="root") {
    13. return;
    14. }
    15.  
    16. while (!xml.atEnd()) {
    17. xml.readNextStartElement();
    18. s = xml.name();
    19. if (s!="a") {
    20. break;
    21. }
    22.  
    23. QString ss = xml.readElementText(QXmlStreamReader::IncludeChildElements);
    24. qDebug("%s", qPrintable(ss));
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    This is not working as I expect. I am getting "test 123" and not "<b>test 123</b>".

    What is the best approach to handle this situation? How can I parse the XML and getting the desired result?

    xml-test1.cpp

    EDIT: similar stackoverflow question: http://stackoverflow.com/questions/5...ing-html-in-qt
    Last edited by elcuco; 15th August 2014 at 21:39.

Similar Threads

  1. Designing a Node Editor (Hint: Blender Node Editor)
    By Mind Calamity in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2011, 17:22
  2. elastic nodes example
    By sajis997 in forum Newbie
    Replies: 2
    Last Post: 3rd August 2011, 16:08
  3. XML: accessing deep nodes
    By mentalmushroom in forum Qt Programming
    Replies: 7
    Last Post: 9th June 2011, 07:56
  4. how to justfy a node is leaf node or not
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2009, 08:40
  5. [QT4] QTreeView and expandable nodes
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2006, 17:52

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
  •  
Qt is a trademark of The Qt Company.