DTD Basics   «Prev 

Embedding the DTD in an XML file

One way to associate a document type to an XML file is to include all DTD statements that define the document type inside the XML file.
Here is a "Hello world!" XML file with DTD statements embedded internally, hello.xml:
<?xml version="1.0"?>
!DOCTYPE p [
 <!ELEMENT p ANY>
]>

Hello world!

Note that:
  1. A document type (DOCTYPE) declaration statement is added right below the "xml" process instruction.
  2. The DOCTYPE statement specifies that "p" is the name of the root element.
  3. The DOCTYPE statement specifies that all other DTD statements are enclosed in this statement enclosed by "[" and "]".
  4. Only one other DTD statement used here, which is an ELEMENT statement. It specifies that the "p" element can have "ANY" thing as its body.
  5. Obviously, the XML document below DTD statements is valid against the defined document type.


hello.xml ; standalone=yes
hello.xml ; standalone=yes

Because the DTD declarations are included within the XML file
Because the DTD declarations are included within the XML file, the standalone attribute will have the value "yes"


s
The !DOCTYPE declaration is used to point to internal DTD declarations
The !DOCTYPE declaration is used to point to internal DTD declarations