这个dtd适合xml文件吗?

时间:2010-12-16 03:03:32

标签: php xml xsd dtd

我有这个xml文件:

data_out.xml

<?xml version="1.0" ?> 
<!DOCTYPE allproperty SYSTEM "data_out.dtd">
<allproperty>
    <aproperty>
      <postcode>ha15rs</postcode> 
      <price>250</price> 
      <imagefilename>home2.gif</imagefilename> 
      <visits>2</visits> 
    </aproperty>
    <aproperty>
      <postcode>ha36gs</postcode> 
      <price>150</price> 
      <imagefilename>home3.gif</imagefilename> 
      <visits>1</visits> 
    </aproperty>
    <aproperty>
      <postcode>ha27se</postcode> 
      <price>300</price> 
      <imagefilename>home4.gif</imagefilename> 
      <visits>4</visits> 
    </aproperty>
    <aproperty>
      <postcode>ha4678</postcode> 
      <price>200</price> 
      <imagefilename>home5.gif</imagefilename> 
      <visits>5</visits> 
    </aproperty>
</allproperty>

DTD文件

data_out.dtd

<!ELEMENT aproperty (postcode,price,imagefilename,visits)>
<!ELEMENT postcode (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT imagefilename (#PCDATA)>
<!ELEMENT visits (#PCDATA)>

当我检查“说allproperty未声明”时,我一直收到错误

1 个答案:

答案 0 :(得分:3)

你必须在DTD中正确声明

<!ELEMENT allproperty (aproperty+)>
<!ELEMENT aproperty (postcode,price,imagefilename,visits)>
<!ELEMENT postcode (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT imagefilename (#PCDATA)>
<!ELEMENT visits (#PCDATA)>