XML中的外部引用DTD

前端之家收集整理的这篇文章主要介绍了XML中的外部引用DTD前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
的test.xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE email SYSTEM "test.dtd">
<email>
<von>test@test.com</von>
<zu>xxx@example.com</zu>
<titel>Hello</titel>
<text>Dear John....;-).</text>
<prior type="schnell"/>
</email>

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

test.dtd中的错误代码

The markup declarations contained or pointed to by the document type declaration must be well-formed. [2]

请帮忙!!

您有重复的DOCTYPE声明.如果要引用外部DTD:

的test.xml

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

test.dtd

<!ELEMENT email (von,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,prior)>
<!ELEMENT von (#PCDATA)>
<!ELEMENT zu (#PCDATA)>
<!ELEMENT titel (#PCDATA)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT prior EMPTY>
<!ATTLIST prior type CDATA #required >
]>
<email>
<von>test@test.com</von>
<zu>xxx@example.com</zu>
<titel>Hello</titel>
<text>Dear John....;-).</text>
<prior type="schnell"/>
</email>

注意:您还缺少先前元素的ELEMENT声明.

猜你在找的XML相关文章