Java Reference
In-Depth Information
Table 13-1.
XML Character Entities
Entity
Character
Represents
&
&
Ampersand
<
<
Less than
>
>
Greater than
'
'
Apostrophe
"
"
Quotation mark
Listing 13-5 shows a simple unparsed character directive example.
Listing 13-5.
An Example of Unparsed Character Data Using XML's CDATA Directive
<?xml version="1.0" encoding="UTF-8"?>
<root>
<![CDATA[
Every character within the CDATA construct is treated as a
regular character; there are no restrictions, so I can write
things like3<4without confusing the XML parser.
]]>
</root>
An XML document may define one or more
namespaces
that define uniquely named
elements and attributes within the document. This permits an XML document to use a
single element or attribute for multiple purposes, such as an
<id>
element that pertains
to both a customer and a product ID. When using namespaces, you use the XML-
restricted
xmlns
tag to define a unique URL that identifies the namespace; namespace
names precede the tag name in tags. You separate the namespace name from the tag
name using a colon, as Listing 13-6 shows.
Listing 13-6.
An Example of XML Namespaces
<?xml version="1.0" encoding="UTF-8"?>
<!-- A simple weather example -->
<wx:weather city="Berkeley" state="CA" country="USA"
xmlns:wx="www.apress.com/rischpater/weather">
<wx:temperatures units="F">
<wx:temperature type="high">76</wx:temperature>
<wx:temperature type="low">56</wx:temperature>
<wx:temperature type="current">56</wx:temperature>
</wx:temperatures>