Datasheet

Reserved Characters in XML
Escape characters are characters preventing execution in a programming language or parser. Thus the <
and > characters must be escaped (using an escape sequence) if they are used in an XML document any-
where other than delimiting tags (elements). In XML, an escape sequence is a sequence of characters
known to the XML parser to represent special characters. This escape sequence is exactly the same as
that used by HTML. The following XML code is invalid:
<country name=”Germany”>West < East</country>
The preceding code can be resolved into XML by replacing the < character with the escape sequence
string
&lt; as follows:
<country name=”Germany”>West &lt; East</country>
The <, >, and & characters are illegal in XML and will be interpreted. Quotation characters of all forms
are best avoided and best replaced with an escape sequence.
Ignoring the XML Parser with CDATA
There is a special section in an XML document called the CDATA section. The XML parser ignores any-
thing within the
CDATA section. So no errors or syntax checking will be performed in the CDATA section.
The
CDATA section can be used to include scripts written in other languages such as JavaScript. The
CDATA section is the equivalent of a <SCRIPT> . . . </SCRIPT> tag enclosed section in an HTML page.
The
CDATA section begins and ends with the strings, as highlighted in the following script example:
<SCRIPT>
<![CDATA[
function F_To_C
{
return ((F – 32) * (5 / 9))
}
]]>
</SCRIPT>
What Are XML Namespaces?
Two different XML documents containing elements with the same name, where those names have differ-
ent meanings, could cause conflict. This XML document contains weather forecasts for three different
cities. The
<name> element represents the name of each city:
<?xml version=”1.0”?>
<WeatherForecast date=”2/1/2004”>
<city>
<name>Frankfurt</name>
<temperature><min>43</min><max>52</max></temperature>
</city>
24
Chapter 1
04_791202 ch01.qxp 10/6/06 10:59 AM Page 24