Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Looking for a XML comparison tool which does not take care of the nodes' order ?

Reply
Thread Tools

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

 
 
for.fun@laposte.net
Guest
Posts: n/a
 
      09-16-2005
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:

<grand-father>
abraham

<father1>
sean

<child1>
arthur
</child1>

<child2>
john
</child2>

</father1>


<father2>
michael

<child1>
peter
</child1>

</father2>

</grand-father>



XML 2:

<grand-father>
abraham
<father2>michael<child1>peter</child1></father2>
<father1>sean<child2>john</child2><child1>arthur</child1></father1>
</grand-father>

 
Reply With Quote
 
 
 
 
pantagruel
Guest
Posts: n/a
 
 
Reply With Quote
 
 
 
 
for.fun@laposte.net
Guest
Posts: n/a
 
      09-17-2005

pantagruel a écrit :

> http://www.deltaxml.com/
> is good
> otherwise
> http://www.google.com/search?hl=en&l...ff&btnG=Search



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.

 
Reply With Quote
 
for.fun@laposte.net
Guest
Posts: n/a
 
      09-19-2005
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text"/>

<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>

<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:call-template>

</xsl:template>

<xsl:template name="walk">

<xslaram name="leftNode"/>
<xslaram name="rightNodes"/>
<xslaram name="currentPath"/>


<!-- Walk the left node while we have some children or some token's
attributes to process -->

<xsl:choose>

<xsl:when test="boolean($leftNode/child::*) or
(not(boolean($leftNode/child::*)) and
boolean(count($leftNode/@*)!=0))">

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

<xsl:variable name="leftNodeAttributes">
<xsl:if test="count($leftNode/@*)!=0">
<xsl:text>{</xsl:text>
<xsl:for-each select="$leftNode/@*">
<xsl:text>@</xsl:text><xsl:value-of
select="name()"/>="<xsl:value-of select="."/>"<xsl:text/>
<xsl:if test="not(position()=last())"><xsl:text>
</xsl:text></xsl:if>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:variable>


<!-- 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"
select="$leftNode/child::*[1]"/>
<xsl:with-param name="rightNodes"
select="$leftNode/child::*[1]/following-sibling::*"/>
<xsl:with-param name="currentPath" select="$newPath"/>
</xsl:call-template>

</xsl:when>


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

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

</xsl:choose>


<!-- 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"
select="$rightNodes[1]/following-sibling::*"/>
<xsl:with-param name="currentPath" select="$currentPath"/>
</xsl:call-template>

</xsl:if>

</xsl:template>

</xsl:stylesheet>

 
Reply With Quote
 
gulin gulin is offline
Junior Member
Join Date: Jun 2008
Posts: 1
 
      06-09-2008
Hi,

Please try A7Soft ExamXML from http://www.a7soft.com

Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how does map take care invalid range for erase()? newbie C++ 2 07-27-2007 06:21 PM
OT: I don't care -- because YOU don't care! TPS Report MCSE 2 10-23-2006 02:51 PM
Do I have to take MS courses in order to take the exams? Ionut Marin MCAD 1 02-09-2004 02:24 PM
Looking For a tool to crawl ASP and compare to a folder of files to see which are used and which are not. Steve Mauldin ASP General 0 02-06-2004 04:15 PM
It will take care of your home rvaduvoor Computer Support 1 12-23-2003 03:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57