Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CDATA type

 
Nancy King
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic