-1

OK so I'm trying to validate the following XML file with the following DTD, but I keep getting the error Attribute "type" must be declared for element type "policy".

The XML file is shown as below:

<?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>

The DTD file is below:

<!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)>
OysterMaker
  • 279
  • 2
  • 13
  • 26

1 Answers1

1

You have no attribute declared in your DTD. If you want your XML to validate properly, you will need to declare the type attribute on the policy element that way (for example):

<!ATTLIST policy
          type       CDATA    #IMPLIED >

There are other possibilities with attribute, to bring you a first view you can have a look at http://www.w3schools.com/xml/xml_dtd_attributes.asp

potame
  • 7,597
  • 4
  • 26
  • 33