2010-12-16 87 views
1

我有這個XML文件:這個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未聲明「

回答

3

您必須在DTD allproperly聲明以及

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

感謝我這樣做,現在即時得到'這個元素allproperty內容不遵循DTD,期待(aproperty),得到了(aproperty aproperty aproperty aproperty)'謝謝+1從我 – getaway 2010-12-16 03:12:06

+2

@getaway:對不起忘了'+' – RageZ 2010-12-16 03:21:01