XML DTD 验证:声明子集中不允许使用字符
XML DTD validation: character not allowed in declaration subset
尽管存在根元素并已将所有属性插入 DTD 的 ATTLIST 中,但我在 w3 验证器上遇到了几个错误:
Error Line 17, Column 9: character "g" not allowed in declaration
subset gender CDATA #REQUIRED>
Error Line 21, Column 45: there is no attribute "gender"
… <person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
Error Line 21, Column 58: there is no attribute "email" … <person
user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
Error Line 29, Column 22: document type does not allow element
"lastdownload" here
<lastdownload> PokemonGo </lastdownload>
Error Line 30, Column 19: document type does not allow element
"lastlogin" here
<lastlogin> 12.03.2016 </lastlogin>
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (person+)>
<!ELEMENT person (firstname,lastname,telephone,city,address, preferences, newsletter, downloads)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT preferences (#PCDATA)>
<!ELEMENT newsletter (#PCDATA)>
<!ELEMENT lastdownload (#PCDATA)>
<!ELEMENT lastlogin (#PCDATA)>
<!ELEMENT downloads (#PCDATA)>
<!ATTLIST person
user CDATA #REQUIRED>
gender CDATA #REQUIRED>
email CDATA #REQUIRED>
]>
<catalog>
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
<firstname> X </firstname>
<lastname> XXXX </lastname>
<telephone> 06666666 </telephone>
<city> ZZZZZ </city>
<address> Azxxxxxh xxx </address>
<preferences> Educational </preferences>
<newsletter> Yes </newsletter>
<lastdownload> PokemonGo </lastdownload>
<lastlogin> 12.03.2016 </lastlogin>
<downloads> 5 </downloads>
</person>
</catalog>
有几个错误需要修复:
- 删除
ATTLIST
. 中多余的 >
个字符
- 将
lastdownload
和 lastlogin
添加到 catalog
的内容模型。
这是应用了所有修复的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (person+)>
<!ELEMENT person (firstname,lastname,telephone,city,address, preferences,
newsletter, lastdownload, lastlogin, downloads)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT preferences (#PCDATA)>
<!ELEMENT newsletter (#PCDATA)>
<!ELEMENT lastdownload (#PCDATA)>
<!ELEMENT lastlogin (#PCDATA)>
<!ELEMENT downloads (#PCDATA)>
<!ATTLIST person
user CDATA #REQUIRED
gender CDATA #REQUIRED
email CDATA #REQUIRED>
]>
<catalog>
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
<firstname> X </firstname>
<lastname> XXXX </lastname>
<telephone> 06666666 </telephone>
<city> ZZZZZ </city>
<address> Azxxxxxh xxx </address>
<preferences> Educational </preferences>
<newsletter> Yes </newsletter>
<lastdownload> PokemonGo </lastdownload>
<lastlogin> 12.03.2016 </lastlogin>
<downloads> 5 </downloads>
</person>
</catalog>
尽管存在根元素并已将所有属性插入 DTD 的 ATTLIST 中,但我在 w3 验证器上遇到了几个错误:
Error Line 17, Column 9: character "g" not allowed in declaration subset
gender CDATA #REQUIRED>
Error Line 21, Column 45: there is no attribute "gender" …
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
Error Line 21, Column 58: there is no attribute "email" …
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
Error Line 29, Column 22: document type does not allow element "lastdownload" here
<lastdownload> PokemonGo </lastdownload>
Error Line 30, Column 19: document type does not allow element "lastlogin" here
<lastlogin> 12.03.2016 </lastlogin>
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (person+)>
<!ELEMENT person (firstname,lastname,telephone,city,address, preferences, newsletter, downloads)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT preferences (#PCDATA)>
<!ELEMENT newsletter (#PCDATA)>
<!ELEMENT lastdownload (#PCDATA)>
<!ELEMENT lastlogin (#PCDATA)>
<!ELEMENT downloads (#PCDATA)>
<!ATTLIST person
user CDATA #REQUIRED>
gender CDATA #REQUIRED>
email CDATA #REQUIRED>
]>
<catalog>
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
<firstname> X </firstname>
<lastname> XXXX </lastname>
<telephone> 06666666 </telephone>
<city> ZZZZZ </city>
<address> Azxxxxxh xxx </address>
<preferences> Educational </preferences>
<newsletter> Yes </newsletter>
<lastdownload> PokemonGo </lastdownload>
<lastlogin> 12.03.2016 </lastlogin>
<downloads> 5 </downloads>
</person>
</catalog>
有几个错误需要修复:
- 删除
ATTLIST
. 中多余的 - 将
lastdownload
和lastlogin
添加到catalog
的内容模型。
>
个字符
这是应用了所有修复的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (person+)>
<!ELEMENT person (firstname,lastname,telephone,city,address, preferences,
newsletter, lastdownload, lastlogin, downloads)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT preferences (#PCDATA)>
<!ELEMENT newsletter (#PCDATA)>
<!ELEMENT lastdownload (#PCDATA)>
<!ELEMENT lastlogin (#PCDATA)>
<!ELEMENT downloads (#PCDATA)>
<!ATTLIST person
user CDATA #REQUIRED
gender CDATA #REQUIRED
email CDATA #REQUIRED>
]>
<catalog>
<person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
<firstname> X </firstname>
<lastname> XXXX </lastname>
<telephone> 06666666 </telephone>
<city> ZZZZZ </city>
<address> Azxxxxxh xxx </address>
<preferences> Educational </preferences>
<newsletter> Yes </newsletter>
<lastdownload> PokemonGo </lastdownload>
<lastlogin> 12.03.2016 </lastlogin>
<downloads> 5 </downloads>
</person>
</catalog>