在XML中将属性类型声明为实体时的验证错误

问题描述 投票:2回答:1

这是我的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'必须是未解析实体的名称。

xml xsd dtd
1个回答
2
投票

作为@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>
© www.soinside.com 2019 - 2024. All rights reserved.