Internal vs. External DTD


The difference between an external and internal DTD is in how it is declared with DOCTYPE.  For an internal DTD, the code is located between the DOCTYPE tags.  The following example shows of how this is done.

Example: <?xml version=”1.0″ standalone=”yes”?>

<!DOCTYPE courses [

<!ELEMENT courses (course)+>

<!ELEMENT course (date,url)>

<!ELEMENT date (#PCDATA)>

<!ELEMENT url (#PCDATA)>

<!ATTLIST courses type CDATA #REQUIRED>

]>

<courses >

<course>

<name>XML Course</name>

<url>http://www.teach.com/xml/course</url>

</course>

<course>

<name>Java Course</name>

<url>http://www.teach.com/java/course</url>

</course>

</courses >

External DTDs are located in a separate document so in order to be used, it must be linked to the XML document by providing a URL of the DTD file. The URL can point to either a local or remote file using relative and absolute references respectively. The following example shows how to setup for an external DTD.

Example: <?xml version=”1.0″ standalone=”no”?>

<!DOCTYPE courses SYSTEM “courses.dtd”>

<courses >

<course>

<name>XML Course</name>

<url>http://www.teach.com/xml/course</url>

</course>

<course>

<name>Java Course</name>

<url>http://www.teach.com/java/course</url>

</course>

</courses >

 

So along with the above example, an example of a possible “courses.dtd” file is the following.

Example: <!ELEMENT courses (course)+>

<!ELEMENT course (date,url)>

<!ELEMENT date (#PCDATA)>

<!ELEMENT url (#PCDATA)>

<!ATTLIST courses type CDATA #REQUIRED>

This entry was posted in XML Tutorial. Bookmark the permalink.

One Response to Internal vs. External DTD

  1. I just added your weblog to my blog roll, I pray you would take into consideration doing the same.

Leave a Reply

Your email address will not be published.