好的,所以我尝试使用以下DTD验证以下XML文件,但我不断收到错误Attribute "type" must be declared for element type "policy".
XML文件如下所示:
<?xml version="1.0"?>
<!DOCTYPE policies SYSTEM "langs.dtd">
<policies>
<description>Policies taken out in January</description>
<policy type="contents">
<policy-number>1234557</policy-number>
<policy-holder>A. Liu</policy-holder>
</policy>
<policy type="buildings">
<policy-number>1234558</policy-number>
<policy-holder>C. Jones</policy-holder>
</policy>
<report-date>01/01/2008</report-date>
</policies>
DTD文件如下:
<!ELEMENT policies (description, policy+, report-date)>
<!ELEMENT policy (policy-number, policy-holder)>
<!ELEMENT policy-number (#PCDATA)>
<!ELEMENT policy-holder (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT report-date (#PCDATA)>
答案 0 :(得分:0)
您的DTD中没有声明属性。如果您希望XML正确验证,则需要在策略元素上声明type
属性(例如):
<!ATTLIST policy
type CDATA #IMPLIED >
属性有其他可能性,为您提供第一个视图,您可以查看http://www.w3schools.com/xml/xml_dtd_attributes.asp