Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

XML Schema Validation in Xerces-Java 2

Learn the capabilities of XML Schema

Nicholas Chase has been involved in Web site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida, USA, and is the author of three books on Web development, including Java and XML From Scratch (Que) and the upcoming Primer Plus XML Programming (Sams). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  This tutorial is for developers who need to build XML Schema support into Xerces-Java based applications. It discusses the XML Schema capabilities of the Xerces-Java 2.x parser and demonstrates their use in a Java application.

Date:  16 Jul 2002
Level:  Intermediate PDF:  A4 and Letter (318 KB | 31 pages)Get Adobe® Reader®

Activity:  11821 views
Comments:  

About this tutorial

Should I take this tutorial?

This tutorial is for developers who need to build XML Schema support into Xerces-Java based applications. It discusses the XML Schema capabilities of the Xerces-Java 2.x parser and demonstrates their use in a Java application.

Familiarity with XML and Java technology is required. The tutorial covers the basics of the W3C XML Schema recommendation, so while it is helpful, no previous XML Schema knowledge is required. For basic XML information, see the XML programming in Java technology tutorial. An understanding of XML namespaces is also helpful; you can find basic background in the Understanding DOM tutorial.

What is this tutorial about?

The original XML specification included Document Type Definitions, or DTDs, which enabled developers to define a grammar, or structure, for their data. Validating parsers, such as IBM's XML4J or its descendant, Xerces, could then validate XML data against this grammar. The W3C XML Schema specification is an attempt to improve on the DTD -- eliminating some of its weaknesses -- and to allow developers to create XML grammars using XML syntax.

Several schema proposals exist, but this tutorial deals with the W3C XML Schema recommendation; this is the specification I mean when this tutorial mentions XML Schema (with an uppercase S). When I use the lowercase schema or schemas, I am referring to documents that I've written or that you might write that conform to the W3C XML Schema Recommendation.

Xerces-Java 1.x provided basic support for XML Schemas, but version 2.x offers essentially complete XML Schema support. This tutorial explains how to use the XML Schema-related features and properties of Xerces-Java to validate documents against an XML Schema document.

The tutorial begins with a quick review of the Document Object Model (DOM) and the Simple API for XML (SAX), and explains how to create a parser for each using Xerces 2.2.0.


Tools

Make sure that the following tools are installed and tested before beginning the tutorial:

  • A Java Virtual Machine, such as the IBM Java machine or Sun's JDK 1.2 or higher must be installed and working on the target machine. You can find links to JVMs for various platforms in Resources. Users of Java 2 version 1.4.x need to make use of the The Endorsed Standards Override Mechanism.
  • The Xerces-Java 2.0 binary files: Apache provides precompiled files, so you don't need the source files. Download the binaries.
  • A plain text editor for creating Java technology applications. If you choose to use an IDE such as VisualAge instead, make sure that the Xerces *.jar files are on the classpath, and that they precede any other XML APIs. (WebSphere Studio includes support for Xerces-J as part of the default install.)

The Endorsed Standards Override Mechanism

Many of the DOM- and SAX-related classes included in Xerces-J are also part of Java 1.4, and under normal circumstances, the versions included with Java will be used instead of those provided with Xerces.

Fortunately, these classes are "endorsed standards," so you can overide the Java version using the Endorsed Standards Override Mechanism by placing the relevant jar files (in this case, xercesImpl.jar) in the appropriate directory. The default location is

%JAVA_HOME%\lib\endorsed

on Windows, or

%JAVA_HOME%/lib/endorsed

on a Linux system.

Developers can also choose a new location by setting the java.endorsed.dirs system property.

Users of older versions of Java need not be concerned with this issue.

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138528
TutorialTitle=XML Schema Validation in Xerces-Java 2
publish-date=07162002
author1-email=nicholas@nicholaschase.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.