Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
Introduction to XML
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
4. Defining document content
  


Symbols in DTDs page 3 of 9


There are a few symbols used in DTDs to indicate how often (or whether) something may appear in an XML document. Here are some examples, along with their meanings:

  • <!ELEMENT address (name, city, state)>

    The <address> element must contain a <name>, a <city>, and a <state> element, in that order. All of the elements are required. The comma indicates a list of items.

  • <!ELEMENT name (title?, first-name, last-name)>

    This means that the <name> element contains an optional <title> element, followed by a mandatory <first-name> and a <last-name> element. The question mark indicates that an item is optional; it can appear once or not at all.

  • <!ELEMENT addressbook (address+)>

    An <addressbook> element contains one or more <address> elements. You can have as many <address> elements as you need, but there has to be at least one. The plus sign indicates that an item must appear at least once, but can appear any number of times.

  • <!ELEMENT private-addresses (address*)>

    A <private-addresses> element contains zero or more <address> elements. The asterisk indicates that an item can appear any number of times, including zero.

  • <!ELEMENT name (title?, first-name, (middle-initial | middle-name)?, last-name)>

    A <name> element contains an optional <title> element, followed by a <first-name> element, possibly followed by either a <middle-initial> or a <middle-name> element, followed by a <last-name> element. In other words, both <middle-initial> and <middle-name> are optional, and you can have only one of the two. Vertical bars indicate a list of choices; you can choose only one item from the list. Also notice that this example uses parentheses to group certain elements, and it uses a question mark against the group.

  • <!ELEMENT name ((title?, first-name, last-name) | (surname, mothers-name, given-name))>

    The <name> element can contain one of two sequences: An optional <title>, followed by a <first-name> and a <last-name>; or a <surname>, a <mothers-name>, and a <given-name>.


Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact