XMLSpy编写DTD出错:Character 'D' is grammatically unexpected

最近在写以下DTD文件的时候出现这样的错误:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE acconts [
<!ELEMENT acconts (acconter)>
<!ELEMENT acconter (accont,description*,ciphertext,attribute+,comment*)>
<!ELEMENT accont (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT ciphertext (#PCDATA)>
<!ELEMENT attribute (#PCDATA)>
<!ELEMENT comment (#PCDATA)>
]>


查了很多资料,也从教程里复制原版的DTD资料,还是出错,无赖之下删掉了DOCTYPE申明,问题得到解决:

<!ELEMENT acconts (acconter)>
<!ELEMENT acconter (accont,description*,ciphertext,attribute+,comment*)>
<!ELEMENT accont (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT ciphertext (#PCDATA)>
<!ELEMENT attribute (#PCDATA)>
<!ELEMENT comment (#PCDATA)>
出错的原因在于在编写DTD文件的时候是不需要加DOCTYPE的,我们在XML引用DTD文件是才需要加(引入外部DTD文件)

我们在编写XML的时候,DOCTYPE的内容如果在XML内,则我们可以这样写:

<?xml version="1.0"?>
<!DOCTYPE note [
  <!ELEMENT note (to,from,heading,body)>
  <!ELEMENT to      (#PCDATA)>
  <!ELEMENT from    (#PCDATA)>
  <!ELEMENT heading (#PCDATA)>
  <!ELEMENT body    (#PCDATA)>
]>
<note>
  <to>George</to>
  <from>John</from>
  <heading>Reminder</heading>
  <body>Don't forget the meeting!</body>
</note>

你可能感兴趣的:(xml,dtd)