Information Technology Reference
In-Depth Information
mentioned, DTDs provide a basic mechanism for defining an XML language,
i.e. the usable tags and attributes in a specific document obeying a particular
DTD, and which elements may appear as subelements of another, etc. List-
ing 2.2 shows the DTD workinggroup.dtd , which defines the elements and
attributes used in our running example.
< ! DOCTYPE people [
< ! ELEMENT people (title,member+) >
< ! ELEMENT member (firstname,lastname,a liation+) >
< ! ATTLIST member chair (yes | no) ”no” >
< ! ELEMENT title (# PCDATA ) >
< ! ELEMENT firstname ( \ # PCDATA ) >
< ! ELEMENT lastname ( \ # PCDATA ) >
< ! ELEMENT a liation ( \ # PCDATA ) >
] >
Listing 2.2. DTDs define the allowed tags and attributes in an XML file
DTDs allow one to define the structure of elements by regular expressions
using the usual symbols '?','*','+', and '—' to denote optional, arbitrary, at
least one, or alternative occurrences, respectively, of elements. Attributes can
be assigned a default value and can be set as required or optional. For text
elements, DTDs do not provide specific datatypes but only the generic PC-
DATA (parseable character data). For attributes, there are several possible
types apart from the generic character data (CDATA), such as IDs (which
need to be unique within a document), and NMTOKENS (essentially, al-
lowed XML attribute and element names). In addition, DTDs allow one to
define commonly used macros as ENTITIES. The well-known &gt; which is
replaced by the greater-than sign ' > ' within the text in an HTML document
is an example for such a macro, and is defined in the HTML DTD as follows:
< ! ENTITY gt CDATA \ & \ #62; >
Obeying to a common schema such as that provided by a DTD (e.g. HTML
documents obey the HTML DTD) allows software to exchange and process
the corresponding documents. The same holds for exchange formats in XML
defined by common usage of a shared DTD. However, DTDs, which orig-
inate from SGML, have several drawbacks with respect to expressivity. In
the context of XML, these have been overcome by another schema definition
language, namely XML Schema, which we shall cover in Section 2.3.2.
Namespaces
The xmlns attribute in the document element of the XML document in List-
ing 2.1 plays a special role. This attribute assigns a namespace URI to the
element. Unlike other attributes which can be freely defined within DTDs
(or in XML Schema as below), the namespace attribute has a special mean-
ing in XML. When given, it defines the namespace for all the attributes and
tags within its scope, which means the element, where it is defined, all its
attributes and subelements, and the attributes of subelements. Namespaces
Search WWH ::




Custom Search