• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CDATA

 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a xml file - it is machine generated. Basically it put everything into CDATA (sample below)- so text inside a CDATA section is ignored by the parser.
but does this not defeat the purpose of using XML?

<desc>
- <![CDATA[ The slide show blah blah blah.
]]>
</desc>
or
<content_id>
- <![CDATA[ 00B0D0E1E189087CDCD80201000009B4
]]>
</content_id>
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main purpose of using CDATA is suppose you have a text with lot of "<" and &&, then instead of writing < ( entity reference ) u can use CDATA so that parser will ignore that. say you have some line like this a<b && a>c && a<d . for parser < is a start of new element.
hth
sunitha
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunitha,
Thanks for your reply. So then if all text is inside CDATA tags what good is it to be in a XML file. Is it not defeating the purpose of a XML file?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the text within a CDATA block would have been interpreted by the XML parser as a single text element anyway, we have lost nothing. If the text would have been interpreted as something else (two XML elements, invalid XML structure causing a parsing error), we have prevented a possibly fatal error.
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse,
Thanks for your reply, so assuming it parses and is valid, what good is it to be a xml document. I have never seen a XML document where the whole file is enclosed in cdata sections.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In preparing the scripts for on-line mock exams I use CDATA to enclose the text of questions, options and answers because the text may contain symbols that XML parsers recognize.
The XML tags provide the structure of the question - I really don't see the point of your objection.
Bill
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William,
I don't realy object, it was just that I didn't understand why one would do this. Although I do know the purpose of it, I and had never seen it used this way. But okay, would you call it good xml programming / standards?
Thanks for you reply.
MM
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic