PDA

View Full Version : How to split QDomDocument to Strings?



vertusd
14th April 2011, 04:32
dom = QDomDocument()
dom.setContent(xml)
#print dom.toString()>>> this works
nodeList=dom.childNodes()
i=0
while i<nodeList.count():
if nodeList.at(i).nodeName() == "root":
root=nodeList.at(i)
i=i+1
i=0
childList=root.childNodes()
while i<childList.count():
if childList.at(i).nodeName() == "schedule":
doc=QDomDocument()
doc.importNode(node,True)
print doc.toString()
i=i+1


<?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

Lykurg
14th April 2011, 07:22
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().