Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
RELAX NG: The Power Is in the Patterns
RELAX NG: The Power Is in the Patterns

Schema languages are languages that allow you to specify the structure of XML instance documents. RELAX NG (see www.relaxng.org) is an XML schema language that is considered to be simple, yet powerful. This article gives an overview of an important concept of the RELAX NG schema language called patterns. The power of RELAX NG can be found in its patterns.

Schema languages also describe the allowed names of elements and attributes that are found in XML instance documents. And they allow you to specify element ordering, occurrence, and allowed content, like simple text, or datatypes, like integers. Some examples of schema languages are W3C XML Schema, RELAX NG, Schematron, and DTD.

RELAX NG differs from other schema languages in that it's built around the concept of patterns. To understand the power of RELAX NG, you must first understand the basic RELAX NG patterns and how they can be combined.

Let's begin by taking a look at the following XML instance document:

<document pages="1" year="2002" > <title>Patterns are fun <author>Tom Gaven</author> <para> This is the <b>first</b> paragraph. </para> <para> And this is the <b>second</b>. </para> <prints>5 60 45</prints> </document>
This XML instance document contains elements and text. To give you an example of the RELAX NG patterns found in this XML instance document, we could say (ignoring attributes) that the pattern for the document element would be element title, followed by element author, followed by one or more para elements. The pattern for the para element would be a mixture of text and element b. The title, author, and b elements all have a similar pattern, text.

Listing 1 is a complete RELAX NG schema document that shows this pattern syntax. The syntax used in the listing is the compact syntax for RELAX NG. This schema can be used to validate the instance document. Line 1 is a top-level declaration that specifies we're using XML Schema datatypes tied to the "xsd" prefix. The keyword "start" specifies the root element of the instance document. (Datatypes, start, element, attribute, text, and list are all keywords.) RELAX NG's compact syntax uses the same occurrence symbols as DTDs (+,?,*).

The RELAX NG patterns are found to the right of the equals (=) sign. Definition names are to the left. Note that patterns can be combined, like the pattern "pages, year, title, author, para+". The comma specifies an ordering of the patterns. You can also group (or nest) patterns using parentheses. The ( text | b )* pattern specifies zero or more sets of text or b elements.

Patterns
Element and attribute patterns

The first two patterns we'll discuss are the patterns for elements and attributes. Following is the (compact) syntax for the element and attribute patterns:

P1. element nameClass { pattern }
P2. attribute nameClass { pattern }

These two patterns are recursive in that they allow other nested patterns. A nameClass is another great feature of RELAX NG, but for now just think of the nameClass as simply the name of the element or attribute. In the schema document lines 3-10 all use the element or attribute pattern.

Datatype patterns
P3. datatypeName params?
P4. datatypeName? DatatypeValue
P5. "text"

Pattern P3 is used on lines 4 and 10 in the schema document. It allows you to specify the datatype allowed for the content of an element or attribute.

Pattern P4 is used on line 5. The text "2002" is the DatatypeValue field. This specifies that the year element must have the content "2002". Pattern P5 is the text pattern. The keyword "text" specifies that text content is allowed.

Ref (Reference) patterns
P6. ref
P7. "(" pattern ")"

Pattern P6 allows patterns to reference definitions, which in turn define other patterns. The ref pattern is used in the schema document in Listing 1 in lines 2, 3, and 8. For example, the "b" reference on the right side of line 8 references the definition (b) on the left side of line 9. Pattern P7 allows patterns to be nested inside parentheses (see line 8 in the schema).

List pattern
P8. list { pattern }

The list pattern allows lists of content (separated by white space) to be specified. Line 10 in the schema specifies that the prints element can contain a "list of integers."

More patterns
Overall, 14 different patterns are supported by RELAX NG, eight of which are discussed above. The other available patterns are mixed, empty, notAllowed, grammar, parent ref, and external ref. The first three allow more controls on content; the last three allow for file and grammar modularity.

Power in Combinations
Individually, RELAX NG's patterns are powerful, but you can also combine them to handle more complex validation scenarios.

Combined patterns
x = element x { ( list { xsd:integer } | b ) }
b = element b { text }

Element x contains either a list of integers or an element b.

x = element x { "1.0" | "NaN" | num }
num = element num { text }

Element x contains either the string "1.0", the string "NaN", or a num element.

x = element x { (a,b)|(a,c) }
a = element a { text }
b = attribute b { text }
c = attribute c { text }

Element x contains (element a and attribute b) OR (element a and attribute c).

RELAX NG patterns are quite powerful, yet easy to learn and use. With their ability to combine, they offer capability not found in either DTDs or XML Schema.

About Tom Gaven
Tom Gaven lives in northern Virginia, and has developed and delivered training on many different technologies. He has authored over 30 courses, including Assembler, C, C++, Java, OS/2, and Windows. He also authored MindQ's Developer Training for Java program. In the last 2 years, he has been architecting and developing products with XML, XSLT, XML Schema, RELAX NG, Java, and Schematron. Tom is currently working on tools and courseware to make XML easier to use. See http://www.xmldistilled.com for more information.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Can you bring services from the cloud to your customers faster and have them adopt it with ease of use or bring the power of bundled services to the fingertips of your clients without creating new rigid ‘apps stove pipes'? Do you want to prevent your business running away to publ...
OCZ Technology Group, a provider of high-performance solid-state drives (SSDs) for computing devices and systems, on Tuesday announced the Z-Drive R4 CloudServ PCI Express (PCIe) flash storage solution, designed to accelerate cloud computing applications and reduce operating expe...
Many organizations have embraced, or are considering, the benefits of cloud computing – speed, flexibility, increased expertise, shared workload, reduced costs, etc. The benefits are many – but so are the risks. What are the threats to cloud security? Which parties assume respons...
In August 2011, SHI Enterprise Solutions (ESS) division launched the SHI Cloud, offering reliable and cost-effective industrial-grade cloud computing platforms. That same division achieved an 82 percent increase in revenue over 2010.
SoftLayer Technologies on Tuesday announced the immediate worldwide availability of SoftLayer Object Storage, a redundant and highly scalable cloud storage service that allows users to easily store, search and retrieve data across the Internet, with optional CDN connectivity, or ...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
A new collaboration between a telecommunications infrastructure firm and a data center services prov...