Results 1 to 2 of 2

Thread: How to split QDomDocument to Strings?

  1. #1
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to split QDomDocument to Strings?

    Qt Code:
    1. dom = QDomDocument()
    2. dom.setContent(xml)
    3. #print dom.toString()>>> this works
    4. nodeList=dom.childNodes()
    5. i=0
    6. while i<nodeList.count():
    7. if nodeList.at(i).nodeName() == "root":
    8. root=nodeList.at(i)
    9. i=i+1
    10. i=0
    11. childList=root.childNodes()
    12. while i<childList.count():
    13. if childList.at(i).nodeName() == "schedule":
    14. doc.importNode(node,True)
    15. print doc.toString()
    16. i=i+1
    To copy to clipboard, switch view to plain text mode 
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <schedule>
    <id>1302680937609</id>
    <type>2</type>
    </schedule>

    <schedule>
    <id>1302680910453</id>
    <type>2</type>
    </schedule>
    </root>


    I want to split a xml into a Stringlist,a string contains a schedule node,but above code print empty string,but if i print dom after setContent(), it worked, why?

    sry for my english and thx in advance
    Last edited by vertusd; 14th April 2011 at 04:40.

  2. #2
    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: How to split QDomDocument to Strings?

    What happens when you print the element without converting it to a document first? See QDomNode::save(). And are you sure your loops are ok? They could be easier: QDomNode::firstChildElement() and QDomNode::nextSiblingElement().

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 19:10
  2. Split QDomDocument to new QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 28th January 2009, 09:59
  3. QDomDocument inside other QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2008, 15:27
  4. how to split a class ?
    By mimmo_kallon in forum Newbie
    Replies: 0
    Last Post: 8th April 2008, 11:37
  5. More appropriate, section or split?
    By ucntcme in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2007, 12:10

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.