Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Comparing XML Documents with Oracle's XDK 10g for Java

Using Oracle's XDK 10g, you can reduce the process of comparing XML documents to a simple set of library calls that let you determine if the documents are the same, see what the differences are, or use the compare information to generate other documents.


advertisement
s a J2EE developer you might sometimes be interested in comparing a modified XML document with the pre-modified version of that document. Or you might want to compare two XML documents that are both based on the same DTD or XML schema. This article is designed to give you the information you need to answer two questions:
  • Is one XML document the same as another?
  • What are the differences between two XML documents?
In this article, I'll show you how to use XDK 10g Production, which provides a mechanism to compare two XML documents and list the differences between them. Oracle XML Developer's Kit (XDK) 10g is a set of APIs, tools and utilities to help you develop XML applications. XDK 10g is available for Java, C and C ++; however, this article discusses only the Java-compatible version. XDK 10g supports DOM 3.0 and XSLT 2.0 specifications. XDK 10g provides a schema validation API to validate XML documents against an XML schema. You can use the XML Class generator API in XDK 10g to bind XML schema to Java classes, and subsequently marshal and unmarshal XML documents. The XML SQL Utility aids in storing XML documents in a RDBMS database. A supplied XSQL servlet combines XML, SQL, and XSLT to generate an XML document from a SQL query.

Preliminary Setup
To get started, first download Oracle's XDK 10g. You need to add the XMLDiff class package to your classpath. Add both <XDK>/lib/xml.jar and <XDK>/lib/xmlparserv2.jar to the classpath, where <XDK> is the directory in which you installed XDK 10g. Using the XMLDiff Class
You use the XMLDiff class in the oracle.xml.differ package to compare two XML documents. The class contains methods to compare two XML documents and enumerating the differences between them. In addition, you can choose to generate an XSLT stylesheet consisting of the differences between the two XML documents. You can then use the stylesheet to convert one of the compared XML documents to the other. This article compares an example XML document named catalog.xml (see Listing 1) with another XML document called catalog2.xml (see Listing 2).

Download the sample code that accompanies this article, create a directory named XMLDiff, and copy the two XML documents catalog.xml and catalog2.xml to that directory. In comparing XML documents the empty (white) spaces in the XML document are also considered as nodes. You should remove white space in XML documents you want to compare if the white space is not required for comparison.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap