Java Reference
In-Depth Information
<Price>$6.99</Price>
</LineItem>
<LineItem>
<Title>The Hunt for Red October</Title>
<Author>Tom Clancy</Author>
<BookType>Hardcover</BookType>
<Price>$18.99</Price>
</LineItem>
</Order>
Clearly, this syntax is simpler to parse with a program and will produce more
predictable results. An application can process and validate information from this
document with confidence.
Notice that XML uses the begin tag...end tag construct in a manner similar
to HTML. XML data is contained inside user-defined elements. For example,
<Title> is the beginning of an element, and </Title> is the end of the element.
Every XML document must conform to these and other requirements in order to
be classified as well formed, or syntactically correct.
Elements can be nested as child elements inside of other elements. Observe how
the LineItem element in the example contains each of these elements: Title , Author ,
BookType , and Price .
D OCUMENT T YPE D EFINITIONS (DTD S )
An XML document not only contains information in a predictable format, it can
also describe the organization of the information it contains. The beginning of an
XML document may contain a document type definition (DTD), or a reference to
an external DTD. This section of the XML document defines the structure of the
document's contents. It identifies the elements that are allowed in this document
and the relationships between the various elements in the document. An XML
parser can use this information to make sure that the document is not only well-
formed (that is, it conforms to the generic XML syntax rules mentioned previ-
ously), but that it is also valid (that is, conforms to the ordering, grouping, and
cardinality rules specified in a DTD).
For example, the XML shopping cart document could contain this partial DTD:
<!ELEMENT Order (LineItem)+>
<!ATTLIST Order orderNumber CDATA #REQUIRED>
<!ELEMENT LineItem (Title, Author+, BookType, Price)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
Search WWH ::




Custom Search