XML
  Home arrow XML arrow Page 2 - 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 - Using the grammar element


    (Page 2 of 4 )

    You may remember from the very first article that I said a RELAX NG implementation will actually transform a schema a bit, and the element element will no longer be the root element. The element that replaces it as the root element is the grammar element. Within this element is a single start element, which houses the main pattern.

    We can easily modify the XML schema to use the grammar element. The existing schema simply needs to be put inside of a start element, which then needs to be put inside of a grammar element. After doing this, the entire XML schema would look like this:

    <grammar xmlns="http://relaxng.org/ns/structure/1.0">
        <start>
            <element name="people" datatypeLibrary=
    "http://www.w3.org/2001/XMLSchema-datatypes">
                <zeroOrMore>
                    <element name="person">
                        <optional>
                            <attribute name="date">
                                <data type="date"/>
                            </attribute>
                        </optional>
                        <interleave>
                            <choice>
                                <element name="zipCode">
                                    <text/>
                                </element>
                                <group>
                                    <element name="city">
                                        <text/>
                                    </element>
                                    <element name="state">
                                        <text/>
                                    </element>
                                </group>
                            </choice>
                            <element name="gender">
                                <choice>
                                    <value type="string">male</value>
                                    <value type="string">female</value>
                                </choice>
                            </element>
                        </interleave>
                    </element>
                </zeroOrMore>
            </element>
        </start>
    </grammar>

    Notice how the namespace declaration has been moved to the grammar element.

    Using the compact syntax, the process is slightly different. In the compact syntax, there is a grammar keyword. After it are placed brackets, and the word start followed by an equal sign is placed within the brackets. The main pattern is then “assigned” to start. The resulting compact schema looks like this:

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

    An instance document will still validate exactly as before.

    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-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek