XML Compare

Mark Hummel

$Id: cmp.html,v 1.2 2004/10/17 22:27:47 mhummel Exp $


Introduction

This module provides a template for comparing two xml documents.

Table of Contents

cmp:diff - Find differences
cmp:cmp - Compare

Name

cmp:diff — Find differences

Synopsis

<xsl:template name="cmp:diff"><xsl:param name="ns1"/><xsl:param name="ns2"/>  ...</xsl:template>

Compare two xml documents and display differences. Two xml documents are defined to be the same if: They have the matching elements and attributes, and that the data in the elements also match. The comparison is order sensitive.

The element names from the documents at the current depth are compared, followed by their values, then any attribute names and values are compared. The process is applied then to the subtrees of the documents.

Notes: If there are leaf nodes in one nodeset which don't exist in the other, the value of those 'extra' elements won't appear as a difference.

Parameters
ns1, ns2

The two nodesets which are to be compared.

Returns

Returns the difference between the documents.

The format of the output is an xml document. A node is added to the result tree for every difference. The node contains the type of difference (e.g element name difference, attribute value difference, etc), the value in the first nodeset and the value in the second nodeset, and the parent node. The indentation level is the depth at which the difference was found relative to the first document.



Name

cmp:cmp — Compare

Synopsis

<xsl:template name="cmp:cmp"><xsl:param name="ns1"/><xsl:param name="ns2"/><xsl:param name="depth"/>  ...</xsl:template>

Recursively compare two xml nodesets, stop when a difference is found and return false. Otherwise return true if the document is identical.

The element names from the documents at the current depth are compared, followed by their values, then any attribute names and values are compared. The process is applied then to the subtrees of the documents.

Notes: If there are leaf nodes in one nodeset which don't exist in the other, the value of those 'extra' elements won't appear as a difference.

Parameters
ns1, ns2

The two nodesets which are to be compared.

Returns

False when the nodesets are not identical, empty otherwise.