1

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 is, 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.

Whats wrong with it?

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

1 Answer 1

1

You should have a look at the item_list[0].childNodes[1].childNodes. These contain probably what you are looking for. For example:

item_list[0].childNodes[11].childNodes[0].nodeValue

is the date

u'2012-08-01'

Nodes of type 1 do not have a nodeValue but childNodes. Nodes of type 3 (text nodes) have a nodeValue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.