XML compare inaccurrate

Having trouble installing Oxygen? Got a bug to report? Post it all here.
csalsa
Posts: 97
Joined: Tue Apr 22, 2008 9:31 am

XML compare inaccurrate

Post by csalsa »

I created an XML Schema file with two type definitions and an element instance. I then copied the XML Schema file to a second one and swapped the order to the two complex types. Then I did an XML compare.

The Oxygen XML compare reported eight differences. I would expect the XML compare to report no differences as schema type definitions can appear in any order in a schema file. I compare XML Schema files up to 25000 lines but as they are generated from a model, the output order of types/elements is the same. But at times I do want an XML, not text, comparison. I would get a similar result by XML formatting both files and use a text difference tool - like WinMerge.

Is there some setting in OxygenXML to compare these two files and have them report no differences?

The files that I used were:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Identifier">
<xs:simpleContent>
<xs:extension base="xs:integer"/>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="Amount">
<xs:sequence>
<xs:element name="amount" type="xs:decimal"/>
<xs:element name="unit" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="number" type="Identifier"/>
<xs:element name="amount" type="Amount"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Amount">
<xs:sequence>
<xs:element name="amount" type="xs:decimal"/>
<xs:element name="unit" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Identifier">
<xs:simpleContent>
<xs:extension base="xs:integer"/>
</xs:simpleContent>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="number" type="Identifier"/>
<xs:element name="amount" type="Amount"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XML compare inaccurrate

Post by george »

Hi,

In general in XML the order of elements matters. What you are looking for it seems more like an XML Schema comparison tool. oXygen offers a number of options that allow you to specify how XML documents should be compared, for instance you can ignore the order of attributes, the namespace prefixes, etc. (for details see http://www.oxygenxml.com/doc/ug-oxygen/ ... -diff.html). However, we do not offer an option for ignoring the elements order in a comparison.

Best Regards,
George
George Cristian Bina
balka
Posts: 1
Joined: Thu Oct 20, 2011 10:47 am

Re: XML compare inaccurrate

Post by balka »

Hi,

sorry, in general order of elements does NOT matter in XML. I have to compare xml files with the feature of ignoring order of elements and attributes. That's the main reason for buying your xml diff tool. I am using now version 4 and I cannot find any option to switch on that feature. I suppose this is still not available?

Best regards,
Alex.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: XML compare inaccurrate

Post by adrian »

Hi,

This has not yet been implemented. We have it logged on our issue tracking tool, I've added you vote.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
tliu
Posts: 2
Joined: Tue Apr 09, 2013 2:00 am

Re: XML compare inaccurrate

Post by tliu »

Hello there
I am in trial period and I was wondering if this feature has been added?
is there a workaround like sorting the xml first?

thanks
Tommy
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: XML compare inaccurrate

Post by adrian »

Hi,

Unfortunately, this feature has not been implemented yet.
As a workaround you could sort both XMLs by using the same sort criteria and them compare them with the Diff tool.
If the data is tabular, you could use the Grid mode from Oxygen for sorting. In Grid mode if the elements/attributes are grouped in a table, you can find sorting actions in the contextual menus on the table headers.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
tliu
Posts: 2
Joined: Tue Apr 09, 2013 2:00 am

Re: XML compare inaccurrate

Post by tliu »

I have two xmls with the following structure where the "RULE" elements are just in different order but they look different to the diff tool. I wasn't able to gifure out how to sort this such that the order of the "RULE" elemetns depends on their inner contents which include other nodes
<DRUG>
<RULE>
<CONDITION>
188L
</CONDITION>
<ACTIONS>
<LEVEL>3</LEVEL>
</ACTIONS>
</RULE>
<RULE>
<CONDITION>
221Y
</CONDITION>
<ACTIONS>
<LEVEL>3</LEVEL>
</ACTIONS>
</RULE>
</DRUG>

thanks
Tommy
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XML compare inaccurrate

Post by george »

Hi Tommy,

A stylesheet like below would sort the RULE elements depending on CONDITION. Hope that helps!

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="DRUG">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="RULE">
<xsl:sort select="CONDITION" order="ascending"/>
<xsl:apply-templates select="./preceding-sibling::text()[1]"/>
<xsl:apply-templates select="."/>
<xsl:if test="position()=last()">
<xsl:apply-templates select="./following-sibling::text()[1]"/>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I tried to preserve also the whitespace nodes so you can get a similar formatting of the result document.

Regards,
George
George Cristian Bina
Post Reply