2011-03-28 64 views
6

的test.xml:外部引用的DTD在XML

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE email SYSTEM "test.dtd"> 
<email> 
<von>[email protected]</von> 
<zu>[email protected]</zu> 
<titel>Hello</titel> 
<text>Dear John....;-).</text> 
<prior type="schnell"/> 
</email> 

test.dtd:在test.dtd

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE email [ 
<!ELEMENT email (von,zu,titel,text,prior)> 
<!ELEMENT von (#PCDATA)> 
<!ELEMENT zu (#PCDATA)> 
<!ELEMENT titel (#PCDATA)> 
<!ELEMENT text (#PCDATA)> 
<!ATTLIST prior type CDATA #REQUIRED > 
]> 

錯誤代碼包含

的標記聲明或指向文檔類型聲明必須格式良好。 [2]

請幫忙!!

回答

13

您有重複的DOCTYPE聲明。如果你想引用外部DTD:

的test.xml

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE email SYSTEM "test.dtd"> 
<email> 
<von>[email protected]</von> 
<zu>[email protected]</zu> 
<titel>Hello</titel> 
<text>Dear John....;-).</text> 
<prior type="schnell"/> 
</email> 

test.dtd

<!ELEMENT email (von,zu,titel,text,prior)> 
<!ELEMENT von (#PCDATA)> 
<!ELEMENT zu (#PCDATA)> 
<!ELEMENT titel (#PCDATA)> 
<!ELEMENT text (#PCDATA)> 
<!ELEMENT prior EMPTY> 
<!ATTLIST prior type CDATA #REQUIRED > 

如果你希望你的DTD作爲XML文件的一部分(內部子集):

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE email [ 
<!ELEMENT email (von,zu,titel,text,prior)> 
<!ELEMENT von (#PCDATA)> 
<!ELEMENT zu (#PCDATA)> 
<!ELEMENT titel (#PCDATA)> 
<!ELEMENT text (#PCDATA)> 
<!ELEMENT prior EMPTY> 
<!ATTLIST prior type CDATA #REQUIRED > 
]> 
<email> 
<von>[email protected]</von> 
<zu>[email protected]</zu> 
<titel>Hello</titel> 
<text>Dear John....;-).</text> 
<prior type="schnell"/> 
</email> 

注意:您還遺漏了您的prior元素的ELEMENT聲明。