Java Reference
In-Depth Information
CDATA Sections
It is possible to embed unparsed character data ( CDATA ) anywhere in a document where character
data can occur. You do this by placing the unparsed character data in a CDATA section, which begins
with <![CDATA[ and ends with ]]> . The data is described as unparsed because the XML processor
will not analyze it in any way, but will make it available to an application. The data within a CDATA
section can be anything at all it can even be binary data. A CDATA section can be used for including
markup in a document that you don't want to have parsed. For instance:
<explanation> A typical circle element is written as:
<![CDATA[
<circle radius="15">
<position x="30" y="50"/>
</circle>
]]>
</explanation>
The lines shown shaded are within a CDATA section, and although they look suspiciously like markup,
an XML processor looking for markup will not scan them. We have used some of the reserved
characters in here without escaping them, but since the data in a CDATA section is not parsed, they will
not be identified as markup.
Element Attributes
You can put additional information within an element in the form of one or more attributes . An
attribute is identified by an attribute name, and the value is specified as a string between single or
double quotes. For example:
<elementname attributename="Attribute value"> ... </elementname>
As we said earlier, empty elements frequently have attributes. Here's an example of an empty element
with three attributes:
<color red="255" green="128" blue="64"></color>
This would normally be written in the shorthand form, like this:
<color red="255" green="128" blue="64" />
You could also use single quotes to delimit an attribute value if you wish.
The names of the three attributes here are red , green , and blue , which identify the primary
components of the color, and the values between 0 and 255 represent the contribution of each primary
color to the result. Attribute names are defined using the same rule as element names. The attributes in
an element follow the element name in the start tag (or the only tag in the case of an empty element)
and are separated from it by at least one space. If a tag has multiple attributes, they must be separated
by spaces. You can also put spaces either side of the = sign but it is clearer without, especially where
there are several attributes. HTML fans should note that a comma separator between attributes is not
allowed in XML and will be reported as an error.
Search WWH ::




Custom Search