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

Implementing Empty and Void Types in XML Schema 1.0

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Wed, 3 Jun 2015 11:56:27 +0000

Implementing Empty and Void Types in XML Schema 1.0

Hi Folks,

Thank you very much for your outstanding responses. I would like to summarize.

Here are two types to add to your XML Schema repertoire: empty and void.

The empty type is implemented using an empty sequence:

    <xs:complexType name="empty">
       
<xs:sequence/>
   
</xs:complexType>

The void type is implemented using an empty choice:

    <xs:complexType name="void">
       
<xs:choice/>
   
</xs:complexType>

Example illustrating the use of the empty type

Scenario: An XML document contains data about a book, including data about whether the book has a hard cover. The hardcover element is declared empty, since its presence indicates that the book has a hard cover:

    <xs:element name="book">
       
<xs:complexType>
           
<xs:sequence>
               
<xs:element name="title" type="xs:string" />
               
<xs:element name="author" type="xs:string" />
               
<xs:element name="date" type="xs:gYear" />
               
<xs:element name="hardcover" type="empty" />
           
</xs:sequence>
       
</xs:complexType>
   
</xs:element>

Here is a sample instance document:

<book>
   
<title>The Unix Philosophy</title>
   
<author>Mike Gancarz</author>
   
<date>1995</date>
   
<hardcover/>
</book>

Example illustrating the use of the void type

Scenario: There is this publicly defined cellphone vocabulary:

 

    <xs:element name="cellphone">
       
<xs:complexType>
           
<xs:sequence>
                
<xs:element name="brand" type="constrained-string" />
               
<xs:element name="model" type="constrained-string" />
               
<xs:element name="weight" minOccurs="0" type="xs:nonNegativeInteger" />
               
<xs:element name="battery" minOccurs="0" type="constrained-string" />
               
<xs:element name="talk-time" minOccurs="0" type="constrained-string" />
               
<xs:element name="service-providers" minOccurs="0" type="constrained-string" />
               
<xs:element name="description" minOccurs="0" type="xs:string" />
           
</xs:sequence>
       
</xs:complexType>
   
</xs:element>

 

It defines an element which a local customization of the vocabulary does wish not to use; namely, the local customization does not want to use the description element because its type is an unconstrained string, which represents a security risk.  The description element is made to disappear entirely from the customized schema using the void type:

 

    <xs:element name="cellphone">
       
<xs:complexType>
           
<xs:sequence>
               
<xs:element name="brand" type="constrained-string" />
               
<xs:element name="model" type="constrained-string" />
               
<xs:element name="weight" minOccurs="0" type="xs:nonNegativeInteger" />
               
<xs:element name="battery" minOccurs="0" type="constrained-string" />
               
<xs:element name="talk-time" minOccurs="0" type="constrained-string" />
               
<xs:element name="service-providers" minOccurs="0" type="constrained-string" />
               
<xs:element name="description" minOccurs="0" type="void" />
           
</xs:sequence>
       
</xs:complexType>
   
</xs:element>

 

Thus we can ensure, using the void type, that any document containing the element we wish to avoid is invalid according to our schema.

 

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