Home arrow XML arrow Page 3 - Datatypes and More in RELAX NG
XML

Datatypes and More in RELAX NG


Welcome to the third part of a three-part series on RELAX NG. In this part, we will discuss datatypes, the grammar element, and creating named patterns. That's a lot of ground to cover, so let's get started.

Author Info:
By: Peyton McCullough
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
August 11, 2008
TABLE OF CONTENTS:
  1. · Datatypes and More in RELAX NG
  2. · Using the grammar element
  3. · Creating named patterns
  4. · Creating named patterns, continued

print this article
SEARCH DEVARTICLES

Datatypes and More in RELAX NG - Creating named patterns
(Page 3 of 4 )

Even though there has been no difference in how the document validates, the explicit creation of the grammar element allows named patterns to be created in order to better organize the document. If you examine the schema, the hierarchy of it gets a bit complex. In the XML schema, some elements are indented quite a bit. While our schema is not very complex in function, it's easy to see how a more complex schema can get real messy.

Named patterns simply allow us to break up the schema into more manageable chunks. Validation won't be affected, only the appearance and manageability of the schema. Using named patterns, a chunk of the schema can be removed from the rest, given a name, and then referenced by name where needed. This will create manageable chunks rather than one giant hierarchy of elements.

To create a named pattern using the XML syntax, the define element is used. The define element must be a child of the grammar element. The pattern is named using the name attribute, and inside of the element is the actual pattern.

The section of the schema dealing with location is probably the most complex part. So, let's turn it into a named pattern. This can be done by simply cutting and pasting the pattern inside of a define element. We'll call the new pattern “location.” Here's what the new element looks like:

<define name="location">
    <choice>
        <element name="zipCode">
            <text/>
        </element>
        <group>
            <element name="city">
                <text/>
            </element>
            <element name="state">
                <text/>
            </element>
        </group>
    </choice>
</define>

Remember, the define element must be a child of the grammar element.

Now the pattern needs to be referenced where it appears in the schema. The ref element is used to accomplish this. Its name attribute must be set to the name of the pattern that's being referenced. So, in the spot formerly occupied by the XML just removed from the schema, the following element is placed:

<ref name="location"/>


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials