Please visit our sponsors !
XML CDATA
All text in an XML document will be parsed
by the parser.
Only text inside a CDATA section is ignored by the parser.
Parsed Data
XML parsers normally parse all the text in an XML document.
When an XML element is parsed, the text between the XML
tags is also parsed:
<message>This text is also parsed</message>
|
The parser does this because XML elements can contain other elements,
like in this example, where the <name> element contains two other elements (first
and last):
<name><first>Bill</first><last>Gates</last></name>
|
and the parser will break it up into sub-elements like this:
<name>
<first>Bill</first>
<last>Gates</last>
</name>
|
Escape Characters
Illegal XML characters have to be replaced by entity references.
If you place a character like "<" inside an XML element, it will
generate an error because the parser interprets it as the
start of a new element. You cannot write something like this:
<message>if salary < 1000 then</message>
|
To avoid this, you have to replace the "<" character with an entity reference, like this:
<message>if salary < 1000 then</message>
|
There are 5 predefined entity references in XML:
< |
< |
less than |
> |
> |
greater than |
& |
& |
ampersand |
' |
' |
apostrophe |
" |
" |
quotation mark |
Entity references always start with the "&" character and end
with the ";" character.Note: Only the characters "<" and "&" are
strictly illegal in XML. Apostrophes, quotation marks and greater than signs are
legal, but it is a good habit to replace them.
CDATA
Everything inside a CDATA section is ignored by the parser.
If your text contains a lot of "<" or "&"
characters - like program code often does - the XML element can be defined as a
CDATA section.
A CDATA section starts with "<![CDATA[" and ends with
"]]>":
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1
}
else
{
return 0
}
}
]]>
</script>
|
In the previous example, everything inside the CDATA section is ignored by
the parser.
Note on CDATA:
A CDATA section cannot contain another CDATA section. If a CDATA section
contains the characters "]]>" or "<![CDATA[" you are
in deep trouble.
Also make sure there are no spaces or line breaks inside the
"]]>" string.
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|