XML
  Home arrow XML arrow Page 4 - 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, continued


    (Page 4 of 4 )

    Recall how the start element was represented in the compact schema. Its content was basically assigned to it, just as if it were a variable in a programming language. Named patterns are created in the same way. In fact, start itself is actually a special named pattern. In order to reference a named pattern elsewhere in the schema, you simply need to place the name of the pattern. The whole process is extraordinarily easy using the compact syntax. Here's the entire compact schema, with the location section made into a named pattern:

    grammar {
        start =
            element people {
                element person {
                    attribute date { xsd:date }?,
                    location
                }*
            }
        location =
            (
                 (element zipCode { xsd:string }
                | (element city { text },
                    element state { text })) &
                    element gender { "male" | "female" }
            )
    }

    It's also possible to reference a pattern within another pattern. Suppose we wanted to modify the location pattern, taking out the section with the city and state element declarations. These could be placed in a new pattern named “cityState” and referenced within the location pattern. The new pattern in the XML schema would look like this:

    <define name="cityState">
        <group>
            <element name="city">
                <text/>
            </element>
            <element name="state">
                <text/>
            </element>
        </group>
    </define>

    And the modified location pattern in the XML schema would look like this:

    <define name="location">
        <choice>
            <element name="zipCode">
                <text/>
            </element>
            <ref name="cityState"/>
        </choice>
    </define>

    Using the compact syntax, the entire modified schema would look like this:

    grammar {
        start =
            element people {
                element person {
                    attribute date { xsd:date }?,
                    location
                }*
            }
        location =
            (
                 (element zipCode { xsd:string }
                | cityState) &
                    element gender { "male" | "female" }
            )
         cityState =
             (element city { text },
              element state {text })
    }

    By now, you've certainly noticed the amazing conciseness of the compact syntax. Whereas the XML schema has become too big to list in its entirety after each change in the schema, the compact schema is small enough to list each time.

    Yet the choice of which syntax to use is entirely up to you, and with either syntax, you can make full use of RELAX NG's amazing functionality. Perhaps the most surprising feature of RELAX NG is that it manages to offer a complete schema solution while still being very simple and easy to use.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 3 Hosted by Hostway
    Stay green...Green IT