X hits on this document





24 / 142

Document type definitions

<name>Jack</name> <age>3</age> <type>cat</type> <color>black</color> </pet> <pet> <name>Blake</name> <age>12</age> <type>dog</type> <color>blue</color> </pet> <pet> <name>Loosey</name> <age>1</age> <type>cat</type> <color>brown</color> </pet> <pet> <name>Stop</name> <age>5</age> <type>pig</type> <color>brown</color> </pet> </pets>

More commonly, DTDs reside outside an XML document since they are intended to be used by many XML files. In this case, the DOCTYPE declaration includes a pointer to a file where the XML elements are described.

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

Whether or not the DTD is internal or external, a list of XML elements needs to be articulated. Each item on the list will look something like !ELEMENT pets (pet+) where "!ELEMENT" denotes an ele- ment, "pets" is the element being defined, and "(pet+)" is the definition. The definitions are the difficult part. There are many different types of values the definitions can include, and only a few of them are de- scribed here.

Names and numbers of elements

First of all, the definitions can include the names of other elements. In our example above, the first de- claration defines and element called pets and it is allowed to include just on other element, pet. Simil- arly, the element defined as pet is allowed to contain four other elements: name, age, type, and color. Each element is qualified by how many times it can occur in the XML document. This is done with the asterisk (*), question mark (?), and plus sign (+) symbols. Each of these symbols have a specific mean- ing:

  • asterisk (*) - The element may appear zero or more times

  • question mark (?) - The element may appear zero or one time, only

  • plus sign (+) - The element appears at least once if not more times


Document info
Document views526
Page views532
Page last viewedWed Jan 18 16:53:20 UTC 2017