Java Reference
In-Depth Information
XMLSchemawasintroducedbytheW3CtoovercomelimitationswithDTD,suchas
DTD'slackofsupportfornamespaces.Also,XMLSchemaprovidesanobject-oriented
approachtodeclaringanXMLdocument'sgrammar.Thisgrammarlanguageprovides
a much larger set of primitive types than DTD's CDATA and PCDATA types. For ex-
ample, you'll find integer, floating-point, various date and time, and string types to be
part of XML Schema.
Note XML Schema predefines 19 primitive types, which are expressed via the
following identifiers: anyURI , base64Binary , boolean , date , dateTime ,
decimal , double , duration , float , hexBinary , gDay , gMonth ,
gMonthDay , gYear , gYearMonth , NOTATION , QName , string , and time .
XML Schema provides restriction (reducing the set of permitted values through
constraints), list (allowing a sequence of values), and union (allowing a choice of
valuesfromseveraltypes)derivationmethodsforcreatingnew simple types fromthese
primitive types. For example, XML Schema derives 13 integer types from decim-
al through restriction; these types are expressed via the following identifiers: byte ,
int , integer , long , negativeInteger , nonNegativeInteger , nonPos-
itiveInteger , positiveInteger , short , unsignedByte , un-
signedInt , unsignedLong , and unsignedShort . It also provides support for
creating complex types from simple types.
AgoodwaytobecomefamiliarwithXMLSchemaistofollowthroughanexample,
such as creating a schema for Listing 10-1 ' s recipe language document. The first step
increatingthisrecipelanguageschemaistoidentifyallitselementsandattributes.The
elements are recipe , title , ingredients , instructions , and ingredi-
ent ; qty is the solitary attribute.
ThenextstepistoclassifytheelementsaccordingtoXMLSchema's content model ,
which specifies the types of child elements and text nodes (see ht-
tp://en.wikipedia.org/wiki/Node_(computer_science) ) that can be
includedinanelement.Anelementisconsideredtobe empty whentheelementhasno
childelementsortextnodes, simple whenonlytextnodesareaccepted, complex ,when
onlychildelementsareaccepted,and mixed whenchildelementsandtextnodesareac-
cepted.Noneof Listing10-1 ' selementshaveemptyormixedcontentmodels.However,
the title , ingredient ,and instructions elementshavesimplecontentmod-
els; and the recipe and ingredients elements have complex content models.
Forelementsthathaveasimplecontentmodel,wecandistinguishbetweenelements
having attributes and elements not having attributes. XML Schema classifies elements
havingasimplecontentmodelandnoattributesassimpletypes.Furthermore,itclassi-
Search WWH ::




Custom Search