Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 346
user547995 Avatar asked Mar 28 '11 06:03

user547995


People also ask

What is internal and external DTD in XML?

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.

How many DTD an XML document reference?

DTD are defined in the Document with the declaration <! DOCTYPE > and each XML document holds one DTD.

What are the types of DTD in XML?

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.

What are the two types of DTD?

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.


1 Answers

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.

like image 150
Daniel Haley Avatar answered Oct 15 '22 06:10

Daniel Haley