XML
  Home arrow XML arrow Page 3 - Datatypes and More in RELAX NG
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Datatypes and More in RELAX NG
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-08-11

    Table of Contents:
  • Datatypes and More in RELAX NG
  • Using the grammar element
  • Creating named patterns
  • Creating named patterns, continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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"/>

    More XML Articles
    More By Peyton McCullough


       · Hello,This is the final part in my series on the RELAX NG schema language. The...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek