[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XML Schema pattern facet quiz

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Wed, 20 Apr 2011 08:11:14 -0400

XML Schema pattern facet quiz
Hi Folks,

Here simpleType "A" is the base of simpleType "B":

    <xs:simpleType name="A">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z]{10}" />
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="B">
        <xs:restriction base="A">
            <xs:pattern value="[a-z]{20}" />
        </xs:restriction>
    </xs:simpleType>

Is that legal?

After all, clearly the pattern facet in "B" is not a restriction (subset) of the pattern facet in "A".

Further, how does it differ from this, where the two pattern facets are embedded in the same simpleType:

    <xs:simpleType name="C">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z]{10}" />
            <xs:pattern value="[a-z]{20}" />
        </xs:restriction>
    </xs:simpleType>

Is "C" equivalent to "A" plus "B"?

Scroll down to see the answers ...










































This is perfectly legal:

    <xs:simpleType name="A">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z]{10}" />
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="B">
        <xs:restriction base="A">
            <xs:pattern value="[a-z]{20}" />
        </xs:restriction>
    </xs:simpleType>

The pattern facet in "B" does not have to restrict/subclass the pattern facet in "A". In fact, the pattern facets are completely independent.

The pattern facets are "and-ed" together.  Consider this element, Test, declared to be of type "B":

  <xs:element name="Test" type="B" />

The value of "B" must consist of the letters a-z and the length must be exactly 10 characters AND exactly 20 characters. Obviously that is impossible, so Test has no valid value.

Compare the above two simpleTypes against this simpleType:

    <xs:simpleType name="C">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z]{10}" />
            <xs:pattern value="[a-z]{20}" />
        </xs:restriction>
    </xs:simpleType>

Pattern facets within a simpleType are "or-ed" together. Suppose the element, Test, is declared to be of type "C":

  <xs:element name="Test" type="C" />

The value of Test must consist of the letters a-z and the length must be exactly 10 characters OR exactly 20 characters. So either of these is valid:

    <Test>abcdefghijabcdefghij</Test>

    <Test>abcdefghij</Test>

Recap:

1. The pattern facets within a simpleType are "or-ed" together.

2. The pattern facets in a base simpleType and the sub-simpleType are "and-ed" together.

3. The pattern facets in a sub-simpleType do not have to restrict/subclass the patterns in the base simpleType.

/Roger


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.