Vous êtes sur la page 1sur 3

VARIOUS OCCURRENCE SYMBOLS USED

1. DEFINING THE ORDER OF OCCURRENCES: When there are a


multiple number of child elements, you must designate the order of
occurrence. There are two ways to notate the order of occurrence.
Using a comma (,) between the child element name and the next
child element name indicates that the child elements will occur in the
order given. Using a vertical line (|) means that either one or the
other child element will occur.
","

Occurs in the order given

"|"

Either one or the other child element occurs

In the following example, the content of "product" is the "product_name"


and "num" elements, occurring once each in that order.
<! ELEMENT product (product_name, num)>
The following is a valid element description for this type of Element Type
Declaration:
<product>
<product_name>television</product_name>
<num>10</num>
</product>
To describe an Element Type Declaration where either the "portable" or
"home" element (child elements of "tel") occurs:
<! ELEMENT tel (portable|home)>
In this case, the following would be an error when describing both the
portable and home elements:
tel
portable/portable
home/home
/tel
2. DEFINING THE NUMBER OF OCCURRENCES: In addition to the order
of occurrence for child element names, the number of occurrences is also
defined in the Content Model. The number of occurrences is designated
with one of three symbols: "*", "+" or "?". The "*" symbol means "may
occur zero or more times." The "+" symbol means "may occur one or more
times." The "?" symbol means "may occur zero times or one time."
As with the notation examples for the Element Type Declaration <!
ELEMENT product product_name, num> shown earlier, not providing
an symbol for the number of occurrences means "must occur once."

"*"

May occur 0 or more times

" "

May occur one or more times

" "

May occur zero times or once

No designation

One time

Under DTD, a programmer may not designate a specific number of


occurrences (e.g. three times, between two and five times, etc.).
For example, output the "customer" and "product" elements (content of
"orderform") in that order. To describe an Element Type Declaration
designating one occurrence for "customer" and zero or more occurrences
for "product", use the following notation:
<!ELEMENT orderform (customer, product*)>
Now, let's describe all of the elements, referencing the notation examples
above.
Use the "dtd" extension when actually creating the document. The following
shows a file named "order.dtd", describing the Purchase Order XML schema
DTD:
order.dtd
<!ELEMENT orderform (customer, product*)>
<!ELEMENT customer (name,address,tel)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT tel (portable | home)>
<!ELEMENT portable (#PCDATA)>
<!ELEMENT home (#PCDATA)>
<!ELEMENT product (product_name, num)>
<!ELEMENT product_name (#PCDATA)>
<!ELEMENT num (#PCDATA)>
LIST1 Valid XML Document for DTD

orderform.xml
<! DOCTYPE orderform SYSTEM "order.dtd">
<orderform>
<customer>
<name>Jenny</name>
<address>Tokyo</address>
<tel>
<portable>555-5555-5555</portable>
</tel>

</customer>
<product>
<product_name>washing machine</product_name>
<num>1</num>
</product>
<product>
<product_name>television</product_name>
<num>2</num>
</product>
</orderform>

Vous aimerez peut-être aussi