spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column21

XML Schemas

Expressing cardinalities of elements

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


XML Schema has more possibilities than DTD for expressing cardinalities on the elements of a document type. In DTD you indicate that a sequence of one only (1), zero or more (*), or one or more (+) elements from a given set can occur. XML Schema uses minOccurs and maxOccurs attributes to define cardinalities:

<element ref="optionalElement" minOccurs="0"/>
<element ref="twoOrMoreElements" minOccurs="2" maxOccurs="unbounded"/>
<element ref="exactlyOneElement" />

The default values for minOccurs and maxOccurs are 1. Another possibility is to use the choice and all elements. The element choice allows only one of its children to appear in an instance, whereas all defines that all child elements in the group may appear at most once in any order. Such constraints are difficult to express in a DTD.

<xsd:choice>
<element ref="EitherThis"/>
<element ref="OrThat"/>
</xsd:choice>

<xsd:all>
<element ref="Ying"/>
<element ref="Yang"/>
</xsd:all/>

Namespaces

An XML Schema definition specifies one vocabulary, the target namespace, possibly using other vocabularies by including them through the use of namespaces:

<xsd:schema targetNamespace='http://www.physics.com/measurements' xmlns:xsd='http://www.w3.org/1999/XMLSchema' xmlns:units= 'http://www.physics.com/units'>

<xsd:element name='units' type='units:Units'/>
<xsd:element name='measurement' type='measurement'/>
<complexType name='measurement'>
<element name='time' type='time'/>
<element name='value' type='value'/>
</complexType>

This mechanism offers the modularity and extensibility needed to build up a grand hierarchy of namespaces, from basic things like addresses up to very specific objects in any subject matter.

Conclusion

XML Schema offers a rich and flexible mechanism for defining XML vocabularies. It promises the next level of interoperability by describing meta-information about XML in XML. Various tools for validating and editing schemas are available from the Apache Project and IBM alphaworks. Start using XML Schema today!

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column21/2.html
Created: Oct 08, 2000
Revised: Oct 08, 2000