Browse DevX
Sign up for e-mail newsletters from DevX


Discover RELAX NG, A Simple Schema Solution : Page 4

With the goals of compact syntax and compatibility, the Regular Language Description for XML (RELAX NG) eases the pain of working with cumbersome DTDs and XSDs.


RELAX NG in Java

The JAXB libraries in the Java Web Services Developer Pack (Java WSDP) 1.5 include functionality for RELAX NG. JAXB 1.5 provided the initial support for RELAX NG grammar.

The example "publicHolidays.rng" in the downloadable code for this article provides the schema for a list of public holidays in US. The following tags specify the package name to be used for the Java classes generated by JAXB:

    <jaxb:package name="publicHoliday"/>

After JAXB generates the Java files, you compile them. In the example code, the RELAXNGExample parses the sample XML file and prints the contents. Independence Day is incorrectly defined as June 4th in the sample publicHoliday.xml file. RELAXNGExample corrects the date within the Java code by setting the month to July, revalidates it, and prints the new contents to the screen.


JAXB makes parsing and loading XML files into Java applications simple; RELAX NG makes defining the XML schemas easy. Use RELAX NG and JAXB in your next enterprise Java application. Why wait, when it's so simple and easy?

Raghu Donepudi, an independent contractor, currently is a technical manager for a federal government agency. He has a master's degree in Computer Science from Lamar University in Texas. He is a Sun-certified Java developer and the author of many software design techniques.
Thanks for your registration, follow us on our social networks to keep up-to-date