Yaron Naveh
Yaron Naveh

Reputation: 24416

How to compare XML documents

I need to compare two XML chunks:

<elem type="p:type1" xmlns:p="myns" />

<elem type="g:type1" xmlns:g="myns" />

They are semantically equivalent once we see that the type attribute is QName and not just a string. Is there a tool that can do such a comparison once I provide the schema? Also, is there such an API?

Upvotes: 3

Views: 3322

Answers (3)

Jakob
Jakob

Reputation: 3662

Meanwhile the diff/patch language XML Patch has been specified and deprecated Microsoft XML Diff. Have a look at this question for possible tools. In particular xmldiff seems to do proper comparison between XML documents.

Upvotes: 0

Dmitry Pavlov
Dmitry Pavlov

Reputation: 28310

You could download Xmldiffpatch.exe tool from the MSDN article "Using the XML Diff and Patch Tool in Your Applications"

Upvotes: 1

Scott Weinstein
Scott Weinstein

Reputation: 19117

There are probably many tools that do this, one of them is Xml Diff and Path, via MS XML downloads

The Microsoft XML Diff and Patch utility can be used for comparing two XML documents and then patching the original document with the differences, to create a final document. The utility can detect structural changes (such as the move of an XML subtree) and can create an Xml Diff Language Diffgram (XDL diffgram or just diffgram) that describes the differences between the two XML documents. The diffgram can then be used to display these differences or perform a patch using the XML Patch tool.

XML Diff performs XML-based comparison of the XML documents, as opposed to a common lexical comparison. Therefore, it

Ignores the order attributes. Ignores insignificant white spaces. Does not differentiate between an empty element () and element with no content (). Does not care about the document encoding.

The tools are usable via cmd line and API.

Upvotes: 1

Related Questions