Next / Previous / Contents / TCC Help System / NM Tech homepage

2.2. Including the DTD inside your XML file

To include the DTD in an XML file, the file should start like this:

    <?xml version='1.0'?>
    <!DOCTYPE root-name [
        dtd-declarations ...

Here's an example of a complete XML file with an internal DTD that defines two element types: a root element <park> and a second-level element <trail>. We'll explain the pieces of the DTD later on.

    <?xml version="1.0"?>
    <!DOCTYPE park [
      <!ELEMENT park (trail*)>
      <!ATTLIST park
          name    CDATA   #IMPLIED>
      <!ELEMENT trail (#PCDATA)>
      <!ATTLIST trail
          dist    CDATA   #REQUIRED
          climb   CDATA   #REQUIRED>
    <park name='Lincoln Natural Forest'>
      <trail dist='3400' climb='medium'>Canyon Trail</trail>
      <trail climb='easy' dist='1200'>Pickle Madden Trail</trail>