我正在尝试验证此XML文档:
<?xml version="1.0"?>
<CONTACTS>
<CONTACT CONTACT_NUM = "1">
<NAME>Alice</NAME>
</CONTACT>
<CONTACT CONTACT_NUM = "2">
<NAME>Bob</NAME>
</CONTACT>
</CONTACTS>
针对以下DTD:
<!ELEMENT CONTACTS ANY>
<!ELEMENT CONTACT (NAME)>
<!ELEMENT NAME (#PCDATA)>
<!ATTLIST CONTACT CONTACT_NUM ID #REQUIRED>
运行
xmllint --dtdvalid test.dtd test.xml
生产:
test.xml:3: element CONTACT: validity error : Syntax of value for attribute CONTACT_NUM of CONTACT is not valid
test.xml:7: element CONTACT: validity error : Syntax of value for attribute CONTACT_NUM of CONTACT is not valid
Document test.xml does not validate against test.dtd
有人发现属性CONTACT_NUM的语法有什么问题吗?
答案 0 :(得分:2)
ID类型属性的值不能以数字开头。它必须与XML规范中的Name
生成匹配,后者排除了初始数字。
<CONTACT CONTACT_NUM = "_1">
或<CONTACT CONTACT_NUM = "ID1">
就可以了。
参考文献: