Java Reference
In-Depth Information
<!ELEMENT recipe (title, ingredients, instructions)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT ingredients (ingredient+)>
<!ELEMENT ingredient (#PCDATA)>
<!ELEMENT instructions (#PCDATA)>
<!ATTLIST ingredient qty CDATA "1">
ThisDTDfirstdeclarestherecipelanguage'selements.Elementdeclarationstakethe
form
<!ELEMENT
name content-specifier
>
,where
name
isanylegalXML
name(itcannotcontainwhitespace,forexample),and
content-specifier
identi-
fies what can appear within the element.
The first element declaration states that exactly one
recipe
element can appear in
theXMLdocument-thisdeclarationdoesnotimplythat
recipe
istherootelement.
Furthermore, this element must include exactly one each of the
title
,
ingredi-
ents
,and
instructions
childelements,andinthatorder.Childelementsmustbe
specifiedasacomma-separatedlist.Furthermore,alistisalwayssurroundedbyparen-
theses.
Thesecondelementdeclarationstatesthatthe
title
elementcontains
parsed char-
acter data
(nonmarkuptext).Thethirdelementdeclarationstatesthatatleastone
in-
gredient
elementmustappearin
ingredients
.The
+
characterisanexampleof
a regular expression that means one or more. Other expressions that may be used are
*
(zero or more) and
?
(once or not at all). The fourth and fifth element declarations
aresimilartothesecondbystatingthat
ingredient
and
instructions
elements
contain parsed character data.
Note
Element declarations support three other content specifiers. You can specify
<!ELEMENT
name
ANY>
to allow any type of element content or
<!ELEMENT
name
EMPTY>
to disallow any element content. To state that an element contains
mixedcontent,youwouldspecify
#PCDATA
andalistofelementnames,separatedby
verticalbars(
|
).Forexample,
<!ELEMENT ingredient (#PCDATA | meas-
ure | note)*>
statesthatthe
ingredient
elementcancontainamixofparsed
characterdata,zeroormore
measure
elements,andzeroormore
note
elements.It
doesnotspecifytheorderinwhichtheparsedcharacterdataandtheseelementsoccur.
However,
#PCDATA
mustbethefirstitemspecifiedinthelist.Whenaregularexpres-
sion is used in this context, it must appear to the right of the closing parenthesis.
Listing 10-7
's DTD lastly declares the recipe language's attributes, of which there
isonlyone:
qty
.Attribute declarations taketheform
<!ATTLIST
ename aname