File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes CDATA type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "CDATA type" Watch "CDATA type" New topic

CDATA type

Nancy King
Ranch Hand

Joined: Jan 06, 2003
Posts: 30
An attribute of CDATA type can contain any character if it conforms to well formedness constraints.. I am not clear about "well formedness constraints". What Kind of "well formedness constraints" should it to conform to?
Could someone help me out?
Joel Amoussou

Joined: Mar 15, 2003
Posts: 15
Dear Nancy,
According to XML1.0, "The string type may take any literal string as a value". The following is the production for attribute values:
[10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
Assuming this DTD:
the following documents are VALID:
<a b="x>y"/>
<a b="x'y"/>
<a b='x"y'/>
But the following documents are NOT VALID:
<a b="x<y"/>
<a b="x&y"/>
The question often asked is: what is the difference between CDATA and NMTOKEN? Let's assume you want to create an attribute href for URLs. A URL contains a // which is not a name token. So you cannot use the NMTOKEN type for href. You will have to use:
Now the value of href can contain a //.
Another example: an attribute of CDATA type can contain a white space. An attribute of type NMTOKEN cannot contain a white space.
The best way to learn all this is to experiment with small documents and a validating parser.
Good Luck!
Joel Amoussou
IBM XML Certification Practice Test
I agree. Here's the link:
subject: CDATA type
It's not a secret anymore!