aspose file tools*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "CDATA type" Watch "CDATA type" New topic
Author

CDATA type

Nancy King
Ranch Hand

Joined: Jan 06, 2003
Posts: 30
Hi:
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?
Thanks,
Nancy
Joel Amoussou
Greenhorn

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:
<!ELEMENT a EMPTY>
<!ATTLIST a
b CDATA #REQUIRED>
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:
<!ELEMENT a EMPTY>
<!ATTLIST a
href CDATA #REQUIRED>
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
http://www.xmlmentor.net/xmlexamsim.htm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CDATA type