O'Reilly logo

XML Pocket Reference by Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Document Type Definitions

A DTD specifies how elements inside an XML document should relate to each other. It also provides grammar rules for the document and each of its elements. A document that adheres to the specifications outlined by its DTD is considered to be valid. (Don’t confuse this with a well-formed document, which adheres to the XML syntax rules outlined earlier.)

Element Declarations

You must declare each of the elements that appear inside your XML document within your DTD. You can do so with the <!ELEMENT> declaration, which uses the this format:

<!ELEMENT elementname 
                  rule>

This declares an XML element and an associated rule, which relates the element logically in the XML document. The element name should not include <> characters. An element name must start with a letter or an underscore. After that, it can have any number of letters, numbers, hyphens, periods, or underscores in its name. Element names may not start with the string xml, in any variation of upper- or lowercase. You can use a colon in element names only if you are using namespaces; otherwise, it is forbidden.

ANY and PCDATA

The simplest element declaration states that between the opening and closing tags of the element, anything can appear:

<!ELEMENT library ANY>

Using the ANY keyword allows you to include both other tags and general character data within the element. However, you may want to specify a situation where you want only general characters appearing. This type of data is better known ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required