Python / Minidom : Iterate on a NodeList

menexceegecit

New Member
I'm making a Python program that parse XML files. I need to iterate over NodeList, but I have an issue doing it with the "for node in NodeList" syntax. Here is a sample of code :\[code\]docToInclude = parse(node.getAttribute("file"))print ("childNode count : " , len(docToInclude.documentElement.childNodes))print ("childNodes : " , docToInclude.documentElement.childNodes)print("")for i in range(0, len(docToInclude.documentElement.childNodes)): print ("i = ", i , "nodeName = " + docToInclude.documentElement.childNodes.nodeName)print("")for elementNode in docToInclude.documentElement.childNodes : print ("node name : " , elementNode.nodeName) node.parentNode.insertBefore(elementNode, insertPosition)\[/code\]Here is the output : \[code\]childNode count : 3childNodes : [<DOM Text node "'\n\n\t'">, <DOM Element: messageList at 0x3a4e570>, <DOM Text node "'\n\n'">]i = 0 nodeName = #texti = 1 nodeName = messageListi = 2 nodeName = #textnode name : #textnode name : #text\[/code\]If I iterate with the for node in NodeList syntax, an element is skipped.Do you have any idea of this problem origin ?
 
Back
Top