Wednesday, 18 September 2013

Python minidom parsing xml gives None or empty string instead of values from xml

Python minidom parsing xml gives None or empty string instead of values
from xml

I am trying to parse SAP results xml file (generated in soapUI) in Python
using minidom and everything goes smoothly until it comes to retrieving
values. No matter what type of node it it, value printed is "None" or just
empty string. Nodes have different types and only value I can get so far
is tag name for element node. When it comes to it's value I get None. For
text one I get '#text' for nodeName, 3 for nodeType, but empty string for
nodeValue
This start to makes me crazy. What is wrong?
The code is:
from xml.dom.minidom import parse, Node
def parseData():
try:
data = parse('data.xml')
except (IOError):
print 'No \'data.xml\' file found. Move or rename the file.'
Milestones = data.getElementsByTagName('IT_MILESTONES')
for node in Milestones:
item_list = node.getElementsByTagName('item')
print(item_list[0].childNodes[1].nodeName)
print(item_list[0].childNodes[1].nodeType)
print(item_list[0].childNodes[1].nodeValue)
while important part of XML structure looks like that:
<IT_MILESTONES>
<item>
<AUFNR>000070087734</AUFNR>
<INDEX_SEQUENCE>2300</INDEX_SEQUENCE>
<MLSTN>1</MLSTN>
<TEDAT>2012-08-01</TEDAT>
<TETIM>09:12:38</TETIM>
<LST_ACTDT>2012-08-01</LST_ACTDT>
<MOBILE>X</MOBILE>
<ONLY_SL/>
<VORNR>1292</VORNR>
<EINSA/>
<EINSE/>
<NOT_FOR_NEXT_MS>X</NOT_FOR_NEXT_MS>
</item>
</IT_MILESTONES>

No comments:

Post a Comment