A content model is a specification of the
internal structure of an element's content.
A content model consists of a set of parentheses
enclosing some combination of child element names, operators
and the #PCDATA keyword. The operators denote the cardinality
and indicate how elements and character data can be combined.
The table shows the operators and their meaning.
||(comma) strict sequence
Taking the first of these, the elements
may be combined in a sequence using a comma delimiting the
list. The figure shows the declaration for a PersonName element
and FruitBasket element. The elements First, Middle and Last
must appear in the order specified. The declaration for FruitBasket
element type could contain Apple or Cherry but not both.
<!ELEMENT PersonName (First, Middle, Last)>
<!ELEMENT FruitBasket (Apple | Cherry)>
The operators seen so far lack something
important: cardinality, such as how many instances of an element
type are permitted? The table shows the cardinality operators.
||Optional; may or may not appear
||Zero or more
||one or more
If no cardinality operator is used, then
the cardinality is one. These operators can be used with elements
or content model groups to form very complicated structures.
Let us now see an example using the FruitBasket element type declaration.
<!ELEMENT FruitBasket (Cherry+, (Apple | Orange)*>
This content model group says that the basket
contains one or more instances of the element type Cherry,
followed by zero or more instances of the choice between Apple
and Orange. Note that all the elements must appear together.
This would lead to an instance as shown.
To indicate mixed content, one must include
#PCDATA in the content model. The elements in the content
model must be separated by the pipe ( | ) operator and the
whole group as a whole declared as having zero or more cardinality.
When using mixed content model, the #PCDATA
keyword must be the first choice in the model. This would
indicate zero or more choices from ItemA, ItemB and #PCDATA.
This could lead to an instance as shown.
This is the text that I wanted to include
Attributes complement and modify elements
by means of associating simple properties with elements. Attributes
are a rich feature in XML that allows us to tie in a lot of information.
In HTML, SRC is an attribute in the IMG
tag. Attributes are declared in XML using the ATTLIST tag.
Each element which has attributes declared
for it will have atleast one ATTLIST that declares the attribute
for the element.
The ATTLIST declaration consists of the
ATTLIST keyword followed by the element to which the attribute
applies, followed by zero or more attribute definitions. For
readability purposes, it is better to place the attribute
definition on a separate line.
Each attribute definition consists of the
name of the attribute, its type and a default definition.
<!ATTLIST ourElement AttributeName CDATA
In the figure, we are declaring a single
attribute AttributeName that must occur in the start-tag of
every instance of ourElement element, and that the value of
the attribute is a character data string (CDATA), #REQUIRED
is the default definition.
An attribute can have one of the several
different defaults that define the way the attribute appears in the document.
There are four defaults for attribute declarations.
They are as shown in the table.
must appear on every instance of element.
optionally appear on an instance of an element.
|#FIXED plus default value
have default value; if attribute does not appear,
value is assumed by the parser.
|Default value only
does not appear, default value assumed by parser.
If attribute appears it may have another value.
If the default attribute value is provided
in the ATTLIST and omitted in the instance of the element
in a document, an XML parser behaves as though the attribute
appeared with the default value. Thus for the example as shown
both the instances are the same.
<!ATTLIST SomeCol color "blue">
From the example, we can see that the declaration
of the color attribute gave us a default value that is blue.
In the first instance, this has been explicitly declared,
but left off in the second instance of the element. A parser
would treat both as having a value of blue for the attribute color.
The attribute type specifies whether the
attribute is needed or not. The table shows the various types
of the attributes and their meaning.
||Character data (String).
||Name uniqu within a given document.
some element bearing an ID attribute Possessing
the same value as the IDREF attribute.
||Series of IDREFs
delimited by whitespaces ENTITY Name of a predefined external entity.
||Series of ENTITY
names delimited by whitespaces.
||A series of
NMTOKENS delimited by whitespaces.
of a set of names indicating notation types declared in the DTD.
of a series of explicitly user-defined values that
the attributes can take on.
Eventually, all the content turns up as
text. When there is an attribute type whose value consists
of just text, it may be declared as CDATA.
The value of the attribute could be of any
character data string of any length. The only restriction
is that the attribute value cannot contain markup. An example
is as shown. As long as the attribute value is simple text,
the parser will declare it to be valid.
<!ATTLIST SomeCol someText CDATA #IMPLIED
<SomeCol someText= "This is a valid
The ID attribute type will have a value
that is a unique identifying name. The value of the ID attribute
must be unique throughout the document. This allows us to
uniquely name an element. No element can have more than one ID for an element.
The attribute type must be #IMPLIED or #REQUIRED
but never #FIXED or defaulted. It however makes no sense if
the default value is provided especially the fixed default
for an ID as that would violate the uniqueness constraint.
What can we do with an ID type attribute
to make it useful? Refer to it, of course. It can be used
to model a one-to-one relationship between two objects modeled
by elements in our vocabulary. As the figure shows, the declaration
attaches a personal identification number to their details
within a file as a unique identifier.
PIN ID #REQUIRED>
Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.