Re: [xsl] Comparing 2 XML Documents

Subject: Re: [xsl] Comparing 2 XML Documents
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 9 Nov 2005 12:45:44 GMT
there are lost of ways of doing this, mainly because there are lots of
different answers.

<x>
 <a/>
 <b/>
 <c/>
</x>

<x>
 <z/>
 <a/>
 <b/>
 <c/>
</x>

Is that one difference, an extra z in the second case, or four
differences
a->z, b-> a, c-> b, c inserted.

textual difference programs have lots of heuristics to generate "small"
difference lists, but the problem is harder in XML where there is more
variablity to start with.

In Xpath2 it's probably easier and there is a built-in deep-equal()
function that can give true/false test whetjer two trees are equivalent
for some (slightly eccentric) notion of equivalence.

One approach is to traverse the first tree, generate an xpath to where
you are (using templates or an extension function) then use that xpath
on the other tree and test what you find.

Another approach is to have a named template that takes teh two trees as
parameters and traverses them in parallel, that's a bit tricker to code
but more efficient if you want to stop if you find any differences, as
you have more direct control over whether or not to recurse into a new
branch.



David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread