Click to See Complete Forum and Search --> : CDATA problem


em4
06-05-2009, 08:38 AM
Hello,

What is the different between this two codes ?

First:

<!DOCTYPE books [
<!ELEMENT books (book_name)>
<!ELEMENT book_name (CDATA)>
]>


and than the in the XML file:

<books>
<book_name>&&&&</book_name>
</books>

This code cause an error.

Second:

<!DOCTYPE books [
<!ELEMENT books (book_name)>
<!ELEMENT book_name (#PCDATA)>
]>

and than the in the XML file:

<books>
<book_name><![CDATA[&&&&]]></book_name>
</books>

This code is perfectly fine

My question is way ?
In both cases it declare that the content of the element "book_name"
will not parsed, so why the first code cause an error ?

Charles
06-05-2009, 09:22 AM
XML parsers don't work that way; the document has to be well-formed without the DTD. That's why scripts and styles in XHTML are PCDATA.