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 profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

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]

Understanding RELAX NG

XML validation that's just right

Nicholas Chase, a Studio B author, 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 several books on Web development, including XML Primer Plus (Sams). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  Many developers find DTD validation too simple (it doesn't use XML syntax, and doesn't enable developers to specify many of the rules needed in the real world) and XML Schema too complicated. RELAX NG represents a compromise: It uses XML syntax, and it enables developers to create most of the same rules as the W3C XML Schema language, but with a greatly simplified syntax. This tutorial explains the concepts behind RELAX NG in both its XML and compact forms.

Date:  04 Dec 2003
Level:  Introductory PDF:  A4 and Letter (97 KB | 35 pages)Get Adobe® Reader®

Activity:  13005 views
Comments:  

Introduction

What is this tutorial about?

As far back as the original XML 1.0 Recommendation, XML has included the ability to validate it, or compare it to a predefined structure. The first version of validation was called the Document Type Definition (DTD), but many developers thought this was too simple: It doesn't use XML syntax, and doesn't enable developers to specify many of the rules needed in the real world. The W3C then developed XML Schema, but many developers thought this was too complicated: It uses XML syntax and enables users to create just about any rule under the sun, but at the cost of adding complexity. Others combined the TREX and RELAX proposals into RELAX NG and many developers think it's just right. It uses XML syntax, and it enables developers to create most of the same rules as the W3C XML Schema language, but with a greatly simplified syntax.

This tutorial explains the concepts behind RELAX NG in both its XML and compact forms. It covers:

  • Creating a RELAX NG schema
  • Elements
  • Attributes
  • Types
  • Optional items
  • Mixed content
  • Restrictions
  • Modularizing a schema
  • Creating these rules using the compact syntax

The tutorial doesn't actually build an application; it uses a command-line application to simply validate the document against the schema document.

Tools

This tutorial doesn't involve any actual programming, but to verify the schema files you create, you'll need a validator. RELAX NG validators exist for a number of different languages, including:

  • Java technology -- Jing (http://www.thaiopensource.com/relaxng/jing.html) and MSV (http://wwws.sun.com/software/xml/developers/multischema/)
  • C -- Libxml2 (http://www.xmlsoft.org/)
  • C# -- Tenuto (http://sourceforge.net/projects/relaxng)
  • Python -- XVIF (http://freshmeat.net/projects/xvif/?topic_id=868)
  • ActiveX -- a DLL, VBRELAXNG (http://www.geocities.co.jp/SiliconValley-Bay/4639/vbrelaxng/vbrelaxng.html)

For more information on available tools, check out http://www.relaxng.org/#software.

Before beginning the tutorial, install your chosen software according to its instructions and make sure you know how to actually validate a file.

This tutorial does assume a basic understanding of XML.

1 of 10 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138367
TutorialTitle=Understanding RELAX NG
publish-date=12042003
author1-email=nicholas@nicholaschase.com
author1-email-cc=