Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

External referenced DTD in XML

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:

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

Error Code in test.dtd

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

Please help!!

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have duplicate DOCTYPE declarations. If you want to reference an external 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 >

If you want your DTD as part of the XML file (internal subset):

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

NOTE: You're also missing an ELEMENT declaration for your prior element.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...