my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes CDATA and PCDATA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "CDATA and PCDATA" Watch "CDATA and PCDATA" New topic
Author

CDATA and PCDATA

R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
I went through this thread.
I have this example from w3school

If I change anyone of these element as CDATA, IE5 gives error :
"Content model is invalid. "
What is the practical use of CDATA ?
Has anyone ever used CDATA for element ??
Can we use it for element at all ??
Any help will be a appreciated.
Thanks in advance.


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
In DTD, there is no CDATA, only PCDATA. It's in the XML document instance where you can markup certain parts of text content with either PCDATA or CDATA blocks.
(PS. I didn't have time to check that so please correct me if I'm wrong)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
I think you are right.
Elements can be only PCDATA. [ or in other words CDATA cant be used in dtd file.]
CDATA, I think, is suppose to be used in the xml file only for the data which you want not to be parsed. [exa: http://www.w3schools.com/xml/xml_cdata.asp]
I tried this and its working fine.

May I conclude it as following points:
1) Only "PCDATA" is used in dtd for element.
2) CDATA is used in xml file for the data which is not suppose to be parsed.
Thanks Lasse
Hari Vignesh Padmanaban
Ranch Hand

Joined: Oct 07, 2003
Posts: 578
Hi,
CDATA is used very rarely in XML documents. Its generally used when you have a lot of textual content like ">","<", "'", "&", """.
The use of CDATA is very rare as it rarely supports teh purpose for which xml was created!!!. (user defined tags). Data inside teh CDATA section is not parsed by teh parser.
So CDATA is generally used when you need to include non-xml data or a lot of pre-defined entities mentioned above.
Elemnts cannot have CDATA as their model. BUT Elemnts can have CDATA sections to store data as shown in the above example by lasse!!!

I guess thats y we also include our code segments in the segment in javaranch so that the entire character set we type (along with white space) is preserved :-). It is not parsed by teh processor used to represent our documents. I guess CDATA is something similar to that !!!
hope this helps
hari
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CDATA and PCDATA
 
Similar Threads
Want to write schema and xml in file
#CDATA and #PCDATA
Validating Parser
DTD and XML
#PCDATA