Microsoft Word Applied xml a toolkit for Programmers Wiley doc




Download 2,96 Mb.
Pdf ko'rish
bet67/131
Sana14.05.2024
Hajmi2,96 Mb.
#232039
1   ...   63   64   65   66   67   68   69   70   ...   131
Bog'liq
Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

Character Data Sections
When we talked about entity references, we mentioned that there was more than one 
way to fix the problem of the parser getting confused by content containing illegal 
characters or non-well formed syntax. One way to duck past the watchful eye of the 
parser is to make the parser simply assume that your content is nothing more than 
character data by dumping that information into a character data
 
(CDATA) section
 
(hence 
the name!). Think of the CDATA section as a cover under which contraband material 
(content containing characters that would otherwise cause non-well formed syntax errors) 
can be smuggled across customs (the XML parser).
Let’s look at our original problem. We want to declare that Faraz is shorter than Alex 
using simple, standard math symbols. Unfortunately, the parser gets upset when we use 
the < character. Well, let’s simply toss our errant statement into a CDATA section. Then, 
our XML snippet would look like this:


The parser would then be tricked into ignoring the content of the CDATA section and 
simply reproducing it as:
Faraz < Alex
Again, this is precisely what we wanted it to look like.
Another example of using CDATA sections is to encode markup itself. Say your XML 
document contains information on how to create HTML pages. In that case, you’re going 
to want to include a lot of markup sections in the document that you would want 
displayed as markup. Let’s say you want to tell a reader how to create a div element 
within a span element in your HTML. Here’s how you could include that information in 
your XML document such that it wouldn’t throw the parser:

Here is how to put a "Div" into a "Span" :

contents of my_div


]]>

Figure 3.8 displays what the parser spits out when it sees the above snippet.Generically, 
CDATA sections are expressed as follows:
as

Download 2,96 Mb.
1   ...   63   64   65   66   67   68   69   70   ...   131




Download 2,96 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



Microsoft Word Applied xml a toolkit for Programmers Wiley doc

Download 2,96 Mb.
Pdf ko'rish