This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CDATA and #PCDATA

 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone let me know what is the exact difference b/w #PCDATA and #CDATA and why #CDATA is not allowed as the content for an element?
As far as i understand, #PCDATA will be parsed by the parser and hence cannot contain any mark-up text like --- < > ' ". I also understand that the parser resolves any of the entity references contained within the #PCDATA that it parses.
What about #CDATA?
Anyone please correct me for any mistakes and clarify
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The keywords #PCDATA and CDATA are pretty much equivalent. One is used for elements and one for attributes. Why are they named differently? Good question.
The only characters which are not allowed in #PCDATA are < and & (unless it represents an entity reference).
The same applies to CDATA. In addition, it can't have " or ', depending on the character that delimits the attribute.
One difference between the two is the fact that #PCDATA is a content model, the only one that specifies what the character stream looks like. CDATA, on the other hand, is one of several ways to restrict the attribute's content.
Cheers,
Dan
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Copied from w3schools
PCDATA
PCDATA means parsed character data.
Think of character data as the text found between the start tag and the end tag of an XML element.
PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.

CDATA
CDATA also means character data.
CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.
 
Samba Siva Rao Potla
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zhang,
You have given below text.
"CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded. "
But..
The internal entity references as an attribute (which is of type CDATA) value will be expanded.
Please let me know if am wrong.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah! Not only the internal entity references, but also the external parsable entity references will be parsed and the value substituted by the parser when entities are used for CDATA of the attributes;
"Only text inside a CDATA SECTION is ignored by the parser." - from w3schools
I guess the CDATA section is the catch here and not the CDATA type used for the attributes;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic