这是我的DTD文件。
?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.0.7 NT (http://www.xmlspy.com) by Manukyan (YSU) -->
<!ENTITY xxx "ccc">
<!ENTITY yyy "ddd">
<!ELEMENT book (author+, title, publisher)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ATTLIST title
aaa ENTITY #IMPLIED
>
这里是相应的DSD文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book SYSTEM "C:\Users\PC\Desktop\XML\XMLDB\XML\BOOK.DTD">
<book>
<author>asd</author>
<title aaa="xxx"/>
<publisher/>
</book>
我得到了一个验证错误。属性'aaa'的值部分'xxx'必须是未解析实体的名称。
作为@Daniel Haley explains in his answer的类似问题,如果你为ccc
添加实体声明和符号(NDATA)声明,那么XML现在是有效的:
<!DOCTYPE book [
<!NOTATION ccc SYSTEM "ccc">
<!ENTITY xxx SYSTEM "ccc" NDATA ccc>
<!ENTITY yyy "ddd">
<!ELEMENT book (author+, title, publisher)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ATTLIST title aaa ENTITY #IMPLIED>
]>
<book>
<author>asd</author>
<title aaa="xxx"/>
<publisher/>
</book>