Databases Reference
In-Depth Information
they are optional;
#FIXED
, meaning that they have a fixed value, indicated in
the definition itself.
An XML document is said to be
valid
with respect to a DTD if it is
syntactically correct according to the DTD. Note that, since elements and
attributes defined in a DTD may appear in an XML document zero (optional
elements), one, or multiple times, depending on their cardinality constraints,
the structure specified by the DTD is not rigid; two distinct XML documents
of the same schema may differ in the number and structure of elements.
XML Schema.
An XML Schema is an XML document that, with respect to DTD, has a
number of advantages. First, an XML Schema is itself an XML document,
consequently it can be easily extended for future needs. Furthermore, XML
Schemas are richer and more powerful than DTDs, since they provide support
for data types and namespaces, which are two of the most significant issues
with DTD.
An element declaration specifies an element name together with a simple
or complex type. A
simple type
is a set of Unicode strings (e.g., decimal,
string, float, and so on) and a
complex type
is a collection of requirements
for attributes, subelements, and character data that apply to the elements
assigned to that type. Such requirements specify, for example, the
order
in
which subelements must appear, and the cardinality of each subelement (in
terms of
maxOccurs
and
minOccurs
, with 1 as default value).
Attribute declarations specify the attributes associated with each element
and indicate attribute
name
and
type
. Attribute declarations may also spec-
ify either a
default
value or a
fixed
value. Attributes can be marked as:
required
, meaning that they must have an explicit value for each occurrence
of the elements with which they are associated;
optional
, meaning that they
are not necessary.
Example 1.
Suppose that we need to define an XML-based language for
describing bank account operations. Figure 1(a) illustrates a DTD stating
that each
account operation
contains a
request
element and one or more
operation
elements. Each
account operation
is also characterized by two
mandatory attributes:
bankAccN
, indicating the number of the bank account
of the requester; and
id
, identifying the single update. Each
request
element
is composed of
date
,
means
,and
notes
elements, where only
date
is required.
Element
operation
is instead composed of:
type
,
amount
,
recipient
,and
possibly one between
notes
and
value
.
Figure 1(b) illustrates an XML document valid with respect to the DTD
in Fig. 1(a).
DTDs and XML documents can be graphically represented as trees.
A DTD is represented as a labeled tree containing a node for each element,
attribute, and value associated with
fixed
attributes. To distinguish elements