DTD Reference: External

When specified externally, the DTD is stored in an external text file with a .dtd extension. This file is then referenced in the prolog of an XML document.

The code snippet on the right displays an XML document with a DTD reference:

    <!DOCTYPE Messages SYSTEM "C:\messagelist.dtd">

where:

  • messagelist.dtd is the name of the external DTD.
  • Messages is the root element.
  • SYSTEM specifies that messagelist.dtd is a file on the C drive of the local file system.

In addition, the code snippet displays the messagelist.dtd file. Note that the definitions begin with an xml declaration tag, similar to all XML documents.

<!-- XML document -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Messages SYSTEM "C:\messagelist.dtd">
    <messages>  <mail>
     <to>you@yourAddress.com</to>      <from>me@myAddress.com </from>
     <subject>Car lights on</subject>
     <text>Owner of vehicle with license plate      454-561, your lights are on!</text>
    </mail> </messages>
<!-- messagelist.dtd-->
<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE messages [
    <!ELEMENT mail (to, from, subject, text)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT subject (#PCDATA)>
    <!ELEMENT text (#PCDATA)> ]>

Click the Next button to continue.