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!!
When a DTD is declared within the file it is called Internal DTD and if it is declared in a separate file it is called External DTD.
DTD are defined in the Document with the declaration <! DOCTYPE > and each XML document holds one DTD.
A DTD is referred to as an internal DTD if elements are declared within the XML files. To refer it as internal DTD, standalone attribute in XML declaration must be set to yes. This means, the declaration works independent of an external source.
DTD stands for Document Type Definition. It is a document that defines the structure of an XML document. It is used to describe the attributes of the XML language precisely. It can be classified into two types namely internal DTD and external DTD.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With