473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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:

<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>

Sep 16 '05 #1
3 1680

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.

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 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">

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

<xsl:otherwise>
<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"/>
</xsl:otherwise>

</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>

Sep 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
133
by: jonathan | last post by:
hey all, I realize that this question might pop up from time to time, but I haven't seen it a while and things might of changed, so - Right now (July 2004) how does mysql stand up in...
24
by: Generic Usenet Account | last post by:
Does anyone have an opinion on how IDL and WSDL compare to each other? Are they equally powerful in their "expressive power"? Sometimes it appears to me that IDL is a little easier for humans to...
29
by: Steven D'Aprano | last post by:
Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: >>> (lambda y: y) < (lambda y: y) False Do the comparison again and things...
1
by: Cremoni | last post by:
I'm looking for a visual scripting language to write poker logic. There must be several things out there, but I haven't been able to find anything suitable. I've seen similar systems in the past. I...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
0
by: Ken Arway | last post by:
GotDotNet has just posted my XSL/XPath tool, ComXT (COMbined Xml Tools): http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=AC6259D9-F7B3-47AA-8ACF-A2D6D0899C38 It does XSL...
0
by: yoni | last post by:
Hi, we got a new SQL Server comparison tool and we're looking for people's opinions of it. our main strengths are that you can also compare databases to a past image of itself, and that our...
28
by: kaferro | last post by:
What is the safest way to make an argv comparison? The code below works. #include <iostream> #include <string> using namespace std; int main(int argc, char *argv) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.