Scenario: Specifying an Element to Contain Subelements: Exactly




Download 2,96 Mb.
Pdf ko'rish
bet73/131
Sana14.05.2024
Hajmi2,96 Mb.
#232039
1   ...   69   70   71   72   73   74   75   76   ...   131
Bog'liq
Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

Scenario: Specifying an Element to Contain Subelements: Exactly 
One Occurrence Allowed
Suppose we wanted to make a 
name
element such that it consists of first_name and 
last_name subelements (as in the above case that was disallowed). The Element Type 
Declaration would be:
Furthermore, because we want the 
first_name
and 
last_name
elements to contain 
PCDATA, we’d have to declare them as such. Their type declarations have been 
discussed above, but here is what the DTD portion defining the entire 
name
element 
would look like:


- 72 -
The parser would interpret this declaration as follows: Elements of type 
name
must 
consist of exactly two subelements called 
first_name
and 
last_name
in that order 
and nothing else

first_name
elements can contain character data. 
last_name
elements can contain character data.
As expected, a legal XML expression of the 
name
type of elements would look like this:

Faraz
Hoodbhoy

Although the actual content of the names can differ (that is, Faraz and Hoodbhoy), 
nothing else could be changed with this declaration. For example,

Hoodbhoy
Faraz

would not work because the order is not as declared.
Also,

Faraz Hoodbhoy

would not work because the element type name was declared to explicitly have element 
content only.
A few notes about PCDATA usage:

All PCDATA type content models are called 
mixed content
models regardless of 
whether they have other elements specified.

The (#PCDATA) content model inherently implies zero or more characters. For 
example, for our above example, both first_name and last_name elements could be 
left blank and the parser would not be upset. It would get upset if the either the 
first_name or the last_name or both element tags were omitted.

Download 2,96 Mb.
1   ...   69   70   71   72   73   74   75   76   ...   131




Download 2,96 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



Scenario: Specifying an Element to Contain Subelements: Exactly

Download 2,96 Mb.
Pdf ko'rish