XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS