File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "CDATA" Watch "CDATA" New topic


Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Sorry for asking a dumb question! Why do we need CDATA in XML when we can use "& lt;" and "& rt;".

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
That's a good question. We might manage without CDATA but I still think it's useful. Consider a large text block containing hundreds and hundreds of special characters you need to encode as an entity reference. Without CDATA, you would need to do a lot more string manipulation compared to using CDATA. With CDATA, you only need to encode the ]]> into [[>

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: CDATA
Similar Threads
how to create a tag to draw rectangle
Nested CDATA Sections
Is CDATA section allowed as a value for the element with type defined as PCDATA ?
CDATA Whitespace issue