Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CDATA and PCDATA

 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic