Java Reference
In-Depth Information
pan with one margarine-smeared side in contact with
pan. Fry for a couple of
minutes and flip. Fry other side for a minute and
serve.
</instructions>
</recipe>
Listing10-1
presentsanXMLdocumentthatdescribesarecipeformakingagrilled
cheesesandwich.ThisdocumentisreminiscentofanHTMLdocumentinthatitconsists
of tags, attributes, and content. However, that's where the similarity ends. Instead of
presentingHTMLtagssuchas
<html>
,
<head>
,
<img>
,and
<p>
,thisinformalre-
cipe language presents its own
<recipe>
,
<ingredients>
, and other tags.
HTML,theydifferfromtheirHTMLcounterparts.Webbrowserstypicallydisplaythe
content between these tags in their titlebars. In contrast, the content between
Listing
orpresentedinsomeotherway,dependingontheapplicationthatparsesthisdocument.
XMLdocumentsarebasedontheXMLdeclaration,elementsandattributes,charac-
terreferencesandCDATAsections,namespaces,andcommentsandprocessinginstruc-
tions.Afterlearningaboutthesefundamentals,you'lllearnwhatitmeansforanXML
document to be well formed, and what it means for an XML document to be valid.
XML Declaration
AnXMLdocumentwilltypicallybeginwiththe
XML declaration
,specialmarkupthat
informsanXMLparserthatthedocumentisXML.TheabsenceoftheXMLdeclaration
in
Listing10-1
revealsthatthisspecialmarkupisn'tmandatory.WhentheXMLdeclar-
ation is present, nothing can appear before it.
The XML declaration minimally looks like
<?xml version="1.0"?>
, where
the nonoptional
version
attribute identifies the version of the XML specification to
whichthedocumentconforms.Theinitialversionofthisspecification(1.0)wasintro-
duced in 1998 and is widely implemented.
Note
The World Wide Web Consortium (W3C), which maintains XML, released
version 1.1 in 2004. This version mainly supports the use of line-ending characters
and the use of scripts and characters that are absent from Unicode 3.2 (see
ht-