这是我的 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>
关于xml - 将属性类型声明为 XML 中的实体时出现验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47962035/