开发者

Error validating CDATA elements with DTD - XML

I'm trying to validate some xml with a DTD I'm writing but I always get a validation error on the elements with CDATA data types. Like this

<!ELEMENT title (#CDATA)> 

I've tried validating using textmate xml validation (XMLlint) and online validators (w3Schools) and I always get this error:

error: ContentDecl : Name or '(' expected

Can anybody explain what's going on here?

Cheers

Example of full xml and dtd (I took this from here so I'd expect it to be valid):

<?xml version="1.0"?>   
<!DOCTYPE bookstore [   
  <!ELEMENT bookstore (name,topic+)>   
  <!ELEMENT topic (name,book*)>   
  <!ELEMENT name (#PCDATA)>   
  <!ELEMENT book (title,author)>   
  <!ELEMENT title (#CDATA)>   
  <!ELEMENT author (#CDATA)>   
  <!ELEMENT isbn (#PCDATA)>   
  <!ATTLIST book isbn CDATA "0">   
  ]>   
<bookstore>   
  <name>Mike's Store</name>   
  <topic>   
    <name>XML</name>   
    <book isbn="123-456-789">   
      <title>Mike's Guide To DTD's and XML Schemas<</title>   
      <author>Mike Jervis</author>   
    </book>   
  </topic>   
</booksto开发者_StackOverflowre>  


Well, the example was a bad one, there's no such thing as (#CDATA) for the element content model.

  <!DOCTYPE bookstore [   
  <!ELEMENT bookstore (name,topic+)>   
  <!ELEMENT topic (name,book*)>   
  <!ELEMENT name (#PCDATA)>   
  <!ELEMENT book (title,author)>   
  <!ELEMENT title (#PCDATA)>   
  <!ELEMENT author (#PCDATA)>   
  <!ELEMENT isbn (#PCDATA)>   
  <!ATTLIST book isbn CDATA "0">   
  ]>   
<bookstore>   
  <name>Mike's Store</name>   
  <topic>   
    <name>XML</name>   
    <book isbn="123-456-789">   
      <title>Mike's Guide To DTD's and XML Schemas</title>   
      <author>Mike Jervis</author>   
   </book>   
  </topic>   
</bookstore>

UPDATE:

The W3C XML specification, http://www.w3.org/TR/2008/REC-xml-20081126, clearly does not allow #CDATA in the content model for elements. Start at production 45 and follow throught to production 51.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜