How can I compare two XML files for equivalency in python?

I would like to be able to compare two xml files from python. This is being used to ensure that an answer received from a web service (SOAP call)  matches predefined expected output. Currently, if there is extra space between xml tags or if any of the the child xml tags are not in the exact same order, this check fails. Alternatively, finding another way to accomplish the same task (check response from a SOAP call against an expected result) is also welcome.

Thank you,
Alex
alex_georgescuAsked:
Who is Participating?
 
peprConnect With a Mentor Commented:
It is not obvious from the question whether you want to check only the content of the XML file or also the structure. If the structure should be checked, look for the XML validation tools. Just the first result of searching (a bit old, anyway)
 "Validating XML with External DTDs using xmlproc"
  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/220472

For the content, you may be interested in parsing the XML file using the xml.etree.ElementTree that is capable also to build a dictionary structure mapping the id's to elements. This way the order of elements is not important and the elements can be easily accessed and processed (compared). See

8.13 xml.etree.ElementTree -- The ElementTree XML API http://docs.python.org/lib/module-xml.etree.ElementTree.html
8.13.1 Functions http://docs.python.org/lib/elementtree-functions.html#l2h-1977
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.