467,119 Members | 1,168 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,119 developers. It's quick & easy.

Looking for a XML comparison tool which does not take care of the nodes' order ?

Hi everybody,
I am looking for a XML comparison tool (I do not mean a standard
char-by-char diff tool but a tool which understand XML syntax)

More precisely, I can have serveral XML structures organized
differently. The XML nodes can store the same data but be organized
differently => in such a case, I would like the diff tool to tell me
that both XML files are identicals.

As far as I am concerned, XML1 and XML2 are identicals (please look at
the sample below).

=> Do you know a command line tool which is able to do this ?
Thanks in advance.
Sample :

XML 1:









XML 2:


Sep 16 '05 #1
  • viewed: 1401
3 Replies

pantagruel a écrit :
is good

Thanks for your reply.
In facts, I already ran the Google search you advised to me but I was
tired of trying the tools : some of them did not work with my previous
post's sample or some other were only graphicals (I am looking for a
command line soft)

I had a quick look to "deltaxml" and it seems good.

Sep 17 '05 #3
I finally quickly wrote the following style sheet (look after these
lines) which flatten the XML input.
I applied the stylesheet to file1/file2, sorted the 2 files and then
applied a classical diff on the 2 files.

Thanks to the flatten format, the 'diff' tell us exactly where the
differences are and there is no need to spend some money for a tool !
-------------------------- Flattening style sheet

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
<xsl:output method="text"/>

<xsl:variable name="newline">

<xsl:template match="/">

<!-- Walk the input XML tree starting from the root node -->

<xsl:call-template name="walk">
<xsl:with-param name="leftNode" select="."/>
<xsl:with-param name="rightNodes" select="./following-sibling::*"/>
<xsl:with-param name="currentPath"></xsl:with-param>


<xsl:template name="walk">

<xsl:param name="leftNode"/>
<xsl:param name="rightNodes"/>
<xsl:param name="currentPath"/>
<!-- Walk the left node while we have some children or some token's
attributes to process -->


<xsl:when test="boolean($leftNode/child::*) or
(not(boolean($leftNode/child::*)) and

<!-- Prepare the attributes' string before printing it to the
output -->

<xsl:variable name="leftNodeAttributes">
<xsl:if test="count($leftNode/@*)!=0">
<xsl:for-each select="$leftNode/@*">
select="name()"/>="<xsl:value-of select="."/>"<xsl:text/>
<xsl:if test="not(position()=last())"><xsl:text>
<!-- Concatenate the iteration's node path to the current node
path -->

<xsl:variable name="newPath" select="concat(concat($currentPath,
concat('/', normalize-space(name($leftNode)))), $leftNodeAttributes)"/>
<!-- Walk down one step -->

<xsl:call-template name="walk">
<xsl:with-param name="leftNode"
<xsl:with-param name="rightNodes"
<xsl:with-param name="currentPath" select="$newPath"/>

<!-- If we reached a leaf then output the full node path -->

<xsl:value-of select="$currentPath"/>
<xsl:if test="boolean($leftNode)">/<xsl:value-of
<xsl:value-of select="$newline"/>

<!-- Walk the right nodes while there are some siblings to process

<xsl:if test="boolean($rightNodes)">

<!-- Walk to the next sibling on the same level -->

<xsl:call-template name="walk">
<xsl:with-param name="leftNode" select="$rightNodes[1]"/>
<xsl:with-param name="rightNodes"
<xsl:with-param name="currentPath" select="$currentPath"/>




Sep 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

133 posts views Thread by jonathan | last post: by
24 posts views Thread by Generic Usenet Account | last post: by
29 posts views Thread by Steven D'Aprano | last post: by
37 posts views Thread by spam.noam@gmail.com | last post: by
reply views Thread by Ken Arway | last post: by
reply views Thread by yoni@nobhillsoft.com | last post: by
28 posts views Thread by kaferro@hotmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.