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

PCDATA and CDATA

 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a xml like this
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE person SYSTEM "test.dtd">
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<person>
<id number="3434&3" dept="ec">
<name>shoba</name>
<address>
<street>hkjfd</street>
<city>jfds</city>
</address>
</id>
</person>
and the corresponding dtd as
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT person (id+)>
<!ELEMENT id (name,address+)>
<!ATTLIST id number CDATA #IMPLIED>
<!ATTLIST id dept (it|ec|ee) #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (street,city,zip?)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT zip (#PCDATA)>
since the attribute value for number is CDATA, this shouldn't complaint about "&" being in there becuase the parser should not parse this value. Am I right or I didn't understand this quiet well?
Thanks for your help
Shoba
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

and it s'd hopefully work.
BTW, i guess PCDATA and CDATA are 2 different things.
PCDATA is used in a DTD to specify
text content and is used with elements
there you w'd probably have
<number>
<![CDATA[<greeting>1234&5</greeting>]]>
</number>
 
Dan Chisham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the parser will choke on the bare & because even #CDATA allows character replacement. This is why the 5 pre-defined character entities: &, < > " &apost; If you use & instead of the &, should work okay.
Hope that helps.
 
Dan Chisham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I MEANT to say was not &apost; but apos; preceded by &. The other predefined character entities are amp; lt; gt; and quot; preceded by &.
(These were all replaced in the previous post).
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I don't clearly understand.
The attribute type of "number" is CDATA and the value for this in xml document is "343&43". Why is it saying the document is not valid. The parser should parse this CDATA value...right?
Please explain in detail.
Thanks
Shoba
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry..correction.
"The parser should not parse this CDATA value"
Thanks
Shoba
 
Deepti Chalichama
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Shoba,
Any attribute declared of type CDATA just denotes string of characters.
Only CDATA sections will not be parsed which is declared as given below
<![CDATA[Nothing between the opening and closing tag will be parsed]]>
Hope this helps
Regards,
Deepti.
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepti, Dan and Karthik
Thanks for your reply.
Now I understand only text within "CDATA Section" will not be parsed.
Thanks
Shoba
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic