|
Schema Validation with JAXP or JDOM
by Deepak Vohra
To maximize the data transferring capabilities of any XML document, that document must be made acceptable to the widest possible audience of users. The easiest way to do this is to make sure that your document conforms to XML schema standards from the very beginning.
But how can you make sure you've done this correctly? And how can you check to see if an existing XML document conforms? The process is called validation. You perform validation on the XML document in question with a schema using parsing APIs.
For instance, to confirm a schema-conforming XML document, you can use the JDOM API to parse your XML document and create a DOM document structure, while also validating the XML document.
If your objective is only to validate an XML document, JAXP 1.3 also provides a validation API.
This article discusses how to validate an XML document using both these validation APIs.
You'll be using a sample XML document called catalog.xml (Listing 1).
The example XML schema is called catalog.xsd (shown in Listing 2). This is the standard to which you want catalog.xml to conform:
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|