Java Reference
In-Depth Information
</svg>
]]>
</example>
</svg-examples>
Listing 10-4
embeds a Scalable Vector Graphics (SVG) [see
ht-
elementofanSVGexamplesdocument.TheSVGdocumentisplacedinaCDATAsec-
tion,obviatingtheneedtoreplaceall
<
characterswith
<
predefinedcharacteren-
tity references.
Namespaces
ItiscommontocreateXMLdocumentsthatcombinefeaturesfromdifferentXMLlan-
guages.NamespacesareusedtopreventnameconflictswhenelementsandotherXML
language features appear. Without namespaces, an XML parser could not distinguish
betweensame-namedelementsorotherlanguagefeaturesthatmeandifferentthings,for
example, two same-named
title
elements from two different languages.
Note
NamespacesarenotpartofXML1.0.Theyarrivedaboutayearafterthisspe-
cificationwasreleased.ToensurebackwardcompatibilitywithXML1.0,namespaces
takeadvantageofcoloncharacters,whicharelegalcharactersinXMLnames.Parsers
that don't recognize namespaces return names that include colons.
A
namespace
isaUniformResourceIdentifier(URI)-basedcontainerthathelpsdif-
ferentiateXMLvocabulariesbyprovidingauniquecontextforitscontainedidentifiers.
ThenamespaceURIisassociatedwitha
namespace prefix
(analiasfortheURI)byspe-
cifying, typically on an XML document's root element, either the
xmlns
attribute by
itself(whichsignifiesthedefaultnamespace)orthe
xmlns:
prefix
attribute(which
signifies the namespace identified as
prefix
), and assigning the URI to this attribute.
Note
Anamespace'sscopestartsattheelementwhereitisdeclaredandappliesto
all of the element's content unless overridden by another namespace declaration with
the same prefix name.
When
prefix
is specified, it and a colon character are prepended to the name of
each element tag that belongs to that namespace—see
Listing 10-5
.
Listing 10-5.
Introducing a pair of namespaces