[XML-SIG] Equivalence test for DOM Nodes?

Roman Kennke roman at interview-machine.com
Tue Nov 25 12:19:12 EST 2003


>
> * roman at 248112.vserver.de
> |
> | Is there a utility function or something to recursivly compare two DOM
> | Nodes for equivalence?
>
> The trouble with that is that there's no definition of what is
> required for two XML fragments to be the same. XML just doesn't have
> any notion of identity for elements.
>
> So while there might be such a method you couldn't really trust it to
> be The One True Element Comparison Method. Not that such a thing
> wouldn't be nice to have... :-(

That's obviously true. There is no such standard. I need this, to
implement some test cases and want to compare plain XML documents for
equivalence, not equality or identity. Equivalent Nodes should meet the
following conditions (there are more, but these are the most important):
1. Their (DOM) Node type must be the same.
2. for Elements:
  - each attribute in one element exists and has the same value in the other
    element and vice versa
  - both elements have the same namespace URI (but may have different
prefixes)
  - both elements have the same name
  - the child elements must be the equivalent (recursion), with adjacent
Text Nodes beeing put together.

3. Text Nodes are equivalent, if they have the same data. There may be an
option to the function, which specifies, if whitespace is significant or
not.

4. The other Node types are pretty straightforward, and since I don't need
them, I don't really care about them.

If nobody has implemented such a function yet, I think I will do it.

Cheers, Roman
--
SOAP for Python
http://interview-machine.com



More information about the XML-SIG mailing list