File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes CDATA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "CDATA" Watch "CDATA" New topic
Author

CDATA

mary morris
Ranch Hand

Joined: Mar 16, 2002
Posts: 97
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

Joined: Dec 12, 2002
Posts: 937
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

Joined: Mar 16, 2002
Posts: 97
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
mary morris
Ranch Hand

Joined: Mar 16, 2002
Posts: 97
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Mar 16, 2002
Posts: 97
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CDATA