Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

#CDATA and #PCDATA

 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

some of the xml articles say that Element's value or Attribute's value type could #CDATA or #PCDATA. i do the follwoings:
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#CDATA)>
<!ELEMENT from (#CDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
</note>
when validated it with XML spy, gives me error saying the file is now well-formed. but when data type is defined as being #PCDATA type, it's FINE.
NOW, WHAT'S WRONG with #CDATA? what's the difference between #CDATA and #PCDATA in terms of their use? could anyone please explain?
thanks.
himal
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himal,
An Element can contain other elements or text.
#PCDATA stands for Parsed Character Data and an Elements data (Elements and Text) must be parsed so therefore it must be #PCDATA if the elements contents is text:
<!ELEMENT name (#PCDATA)>
#CDATA stands for Character Data and is NOT parsed. Attributes are not parsed by the parser so they must be referred to as Character Data.
<!ATTLIST name first CDATA >
I hope this helps and maybe someone can add to this!
[ September 20, 2002: Message edited by: Aaron O'Brien ]
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himal:
#PCDATA (parsed character data)is for elements, CDATA (note: no # sign!)is for attributes. See below:
<!ELEMENT sample (#PCDATA) >
<!ATTLIST sample version CDATA "1.0" >
HTH
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim!
 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys. appreciate your clarification.
himal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic