[XML-SIG] comparing xml documents

Mark McEahern marklists@mceahern.com
Wed, 29 Aug 2001 19:00:04 -0700


> I'm not sure.  The following are semantically equivalent:
> 	<a foo='fooval' bar='barval'/>
> 	<a bar='barval' foo='fooval'></a>
> 	<a xmlns='' bar='barval' foo='fooval'/>
> Should the compare the same?  Probably.  I'd be surprised if the toxml
> method worked.

Believe it or not, xml.dom.minidom squirts out identical xml for the first
two.  It pukes on the third one, though:

>>> s3 = "<a xmlns='' bar='barval' foo='fooval'/>"
>>> d3 = parseString(s3)
>>> d3.toxml()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python21\_xmlplus\dom\minidom.py", line 86, in toxml
    self.writexml(writer)
  File "C:\Python21\_xmlplus\dom\minidom.py", line 891, in writexml
    node.writexml(writer, indent, addindent, newl)
  File "C:\Python21\_xmlplus\dom\minidom.py", line 571, in writexml
    _write_data(writer, attrs[a_name].value)
  File "C:\Python21\_xmlplus\dom\minidom.py", line 265, in _write_data
    data = replace(data, "&", "&amp;")
  File "c:\python21\lib\string.py", line 369, in replace
    return s.replace(old, new, maxsplit)
AttributeError: 'None' object has no attribute 'replace'

Thanks for the tip about C14N--I'll have to check that out!

// mark