Java Reference
In-Depth Information
<!ELEMENT breakfast ((tea|coffee), orangejuice?,
((egg+, (bacon|sausage)) | cereal) , toast)>
This states that <breakfast> content is either a <tea> or <coffee> element, followed by an
optional <orangejuice> element, followed by either one or more <egg> elements and a <bacon> or
<sausage> element, or a <cereal> element, with a mandatory <toast> element bringing up the
rear. However, while you can produce mind-boggling productions for defining elements it is wise to
keep things as simple as possible.
After all this complexity, we mustn't forget that an element may also be empty, in which case it can be
defined like this:
<!ELEMENT position EMPTY>
This states that the <position> element has no content. Elements can also have attributes so let's take
a quick look at how they can be defined in a DTD.
Defining Element Attributes
You use an ATTLIST declaration in a DTD to define the attributes for a particular element. As you
know, attributes are name-value pairs associated with a particular element and values are typically, but
not exclusively, text. Where the value for an attribute is text, it is enclosed between quotation marks, so
it is always unparsed character data. Attribute values that consist of text are therefore specified just as
CDATA . No preceding # character is necessary in this context since there is no possibility of confusion.
We could declare the elements for a document containing circles as follows:
<?xml version="1.0"?>
<!DOCTYPE circle
[
<!ELEMENT circle (position)>
<!ATTLIST circle
radius CDATA #REQUIRED
>
<!ELEMENT position EMPTY>
<!ATTLIST position
x CDATA #REQUIRED
y CDATA #REQUIRED
>
]>
<circle radius="15">
<position x="30" y="50"/>
</circle>
Search WWH ::




Custom Search