PDA

View Full Version : childNodes return unexpected nodes



julida
17th February 2011, 05:08
Hi all,

I have some problems related to QDomNodeList QDomNode::childNodes () const
For example, I have xml content as the following:


<?xml version='1.0' encoding='utf-8'?>
<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 &#xa; &#xa;xliff-core-1.2-transitional.xsd" >
<file original="String" product-name="String" category="String" build-num="String" target-language="en-us" tool="manual" datatype="plaintext" source-language="en-us" xml:space="default" product-version="String" date="2001-12-17T09:30:47-05:00" ts="String" >
<body>
<group merged-trans="yes" >
<trans-unit id="_1_ski_374" approved="no" >
<source>a contact-email</source>
<target equiv-trans="no" state="needs-translation" >%d áž‘áŸ†áž“áž¶áž€áŸ‹áž‘á Ÿ†áž“áž„</target>
</trans-unit>
<trans-unit id="_1_ski_383" approved="no" >
<source>%d contact-emails.</source>
<target equiv-trans="no" state="needs-translation" >%d contact-emails.sdf</target>
</trans-unit>
</group>
</body>
</file>
</xliff>





fileNodes = []
fileNodes = xliff.xlifffile.document.firstChildElement(xliff.x lifffile.rootNode).childNodes()
for k in range(fileNodes.count()):
if fileNodes. at(k).nodeName() == 'file':
_units = fileNodes.at(k).firstChildElement(xliff.xlifffile. bodyNode).childNodes()
for i in range(_units.count()):
print i, _units.at(i).nodeName()


Output:
0 #text
1 group
2 #text

In my code, I want to get direct child nodes of <body>, and my expected output should be:
0 group

I was wondering where is the #text come from?

Thanks for you help,
Da

AsG
7th June 2011, 07:32
are you sure there are no comments in between, because the call reads the comment as a child too!