Java Reference
In-Depth Information
21.3.1 Tag definitions, DTD, Schema,
and XML namespaces
The need for universal agreement between client and servers on the naming and
meaning of XML tags is obvious. A server requires an XML document that uses
the “correct” tags and that has “proper” values for each tag. Everything in XML is
encoded as strings, but a string with a decimal point in it would be inappropriate
in a field that is expected to be an integer. Some elements may be required, some
optional. As in the example above, some tags can appear nested within others.
The nesting can go to any depth, but knowing just what is nested within what
is important. It is clear that there must be some way of communicating among
users of XML which tags are to be used and how they should nested, what kinds
of data values are expected, etc.
There are two standards in use that address the definition of legal and illegal
XML tags - the Document Type Definition (DTD) and the newer and more general
XML Schema notation. While discussing these is well beyond the scope of this
book, both provide techniques to declare which XML tags should appear in a
document, which elements are required and which are optional, how they should
be nested, etc.
Many industries have created their own specifications of valid XML documents
to be used in their particular industry. Some non-profit standards bodies have
provided XML definitions suited to various tasks. These “standard” XML formats
are defined using either DTD or XML Schema.
A closely related concept is that of XML namespaces, which become impor-
tant in complex XML documents [4]. To avoid name collisions, particularly when
common tag names are used, it is possible to prefix a tag name with the name of
the namespace to which it belongs. For a contrived example, suppose there is a
namespace for the life expectancy calculation XML document. Then we would
prefix each tag name with the namespace name. In practice, to avoid lengthening
tag names too much, an abbreviation of the namespace is used. If the abbre-
viation life: is used, then the XML document introduced above would look
like this:
<life:LifeExpectancyParameters>
<life:Name>
<life:FirstName>Jackson</FirstName>
<life:LastName>Turner</LastName>
</life:Name>
<life:Age>49</life:Age>
<life:Sex>Male</life:Sex>
<life:Smoker>No</life:Smoker>
</life:LifeExpectancyParameters>
Each tag name is prefixed with life: which avoids any collision with another
tag named, for example, < FirstName > elsewhere in the document.
Search WWH ::




Custom Search