*:96

Rounded curve

Internet application
protocols and standards

 

 

How to combine DTD and XML in a single file

Instead of two separat files, a DTD file and an XML file, you can combine both in a single file. This example show how to do it.

Separate DTD file family.dtd:


<!ELEMENT family (father,mother,child*)>
<!ELEMENT father (#PCDATA)>
<!ELEMENT mother (#PCDATA)>
<!ELEMENT child (#PCDATA)>

Separate XML file family.xml:


<?xml version="1.0" standalone="no"?>
<!DOCTYPE family SYSTEM "http://www.dsv.su.se/~jpalme/internet-course/xml/family.dtd">
<family>
<father>John</father>
<mother>Margaret</mother>
<child>Eve</child>
<child>Peter</child>
</family>

Combined XML-DTD-file family-combined.xml:


<?xml version="1.0" standalone="no"?>
<!DOCTYPE family
[<!ELEMENT family (father,mother,child*)>
<!ELEMENT father (#PCDATA)>
<!ELEMENT mother (#PCDATA)>
<!ELEMENT child (#PCDATA)>]>
<family>
<father>John</father>
<mother>Margaret</mother>
<child>Eve</child>
<child>Peter</child>
</family>

More about this course