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:
- A document type (DOCTYPE) declaration statement is added right below the "xml" process instruction.
- The DOCTYPE statement specifies that "p" is the name of the root element.
- The DOCTYPE statement specifies that all other DTD statements are enclosed in this statement enclosed by "[" and "]".
- 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.
- Obviously, the XML document below DTD statements is valid against the defined document type.