File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Product and Other Certifications and the fly likes PCDATA and CDATA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "PCDATA and CDATA" Watch "PCDATA and CDATA" New topic
Author

PCDATA and CDATA

Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
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

Joined: Mar 06, 2001
Posts: 1209
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

Joined: Jun 03, 2002
Posts: 9
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.


IBM Certified Developer - XML and Related Technologies<br />CXE (Certified XML Expert)<br />Sun Certified Web Component Developer<br />Sun Certified Java 2 Programmer<p>Dan
Dan Chisham
Greenhorn

Joined: Jun 03, 2002
Posts: 9
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

Joined: Mar 29, 2001
Posts: 68
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

Joined: Mar 29, 2001
Posts: 68
I'm sorry..correction.
"The parser should not parse this CDATA value"
Thanks
Shoba
Deepti Chalichama
Greenhorn

Joined: May 01, 2002
Posts: 25
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

Joined: Mar 29, 2001
Posts: 68
Hi Deepti, Dan and Karthik
Thanks for your reply.
Now I understand only text within "CDATA Section" will not be parsed.
Thanks
Shoba
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: PCDATA and CDATA