How to Use the Doctype Tag in XML

XML allows users to create structure in a one-dimensional file. The file needs to be error free so any browser or other XML parser can understand it. The Document Type Definition is where the error-free specification for a perfect XML document resides. The Document Type Definition can be a separate file or it can be contained in the XML file it describes. When the Document Type Definition is in the XML file, it is contained in the DOCTYPE tag. When the Document Type Definition is in a separate file, the XML DOCTYPE tag contains a pointer, in the form of a URL, to that file. An internal Document Type Definition works well for small, simple files and external is better for complicated scenarios or where the Document Type Definition will be shared between more than one XML file.

Things You'll Need

  • An XML parser
Show More

Instructions

  1. Create an XML Document

    • 1

      Create an XML document using either a text editor or an XML development environment. For example:
      <?xml version="1.0"?>
      <root>
      </root>

    • 2

      Decide on an internal or external Document Type Definition.

    Use the Doctype Tag in XML

    • 3

      Add the Doctype tag to your XML document. For example, if using an internal Document Type Definition, the Doctype tag for the sample XML file would look like this:
      <!DOCTYPE rootdoc [
      <!ELEMENT root (#PCDATA)>
      ]>

Tips & Warnings

  • Most modern Internet browsers have a built in XML parser and can be used to view XML files.

  • XML documents must be both valid and well formed to be interpreted correctly by an XML parser.

Related Searches:

Resources

Comments

You May Also Like

Related Ads

Featured