站内搜索: 请输入搜索关键词
当前页面: 图书首页 > XML and Java: Developing Web Applications, Second Edition

XML and Java: Developing Web Applications, Second Edition

[ directory ] Previous Section Next Section

9.1 Introduction

XML allows users to choose appropriate names (such as WeatherReport and department) for tags and attributes. By using a collection of appropriate names for elements and attributes, the user can create XML documents appropriate for a particular application.

A schema formally describes permissible XML documents for a particular application. That is, a schema describes permissible names for tags and attributes and permissible structural relationships between such tags and attributes. In other words, a schema provides a markup vocabulary. The DTD of XML 1.0 provides such schemas. DTDs have been used for many years to specify markup vocabularies based on XML and its predecessor, SGML.

However, with the dramatic progress of XML, the following disadvantages of DTDs have come to be widely recognized.

Peculiar syntax

The syntax of DTDs is very different from that of XML documents. In fact, a DTD consists of <!ELEMENT ... >, <!ATTLIST ...>, and <!ENTITY ... > declarations, which are neither tags nor attributes. Moreover, parameter entities, which are macros for DTDs, are often used to represent such declarations. Many people believe that this peculiar syntax makes DTDs harder to learn.

The peculiar syntax of DTDs also makes it difficult to develop software tools for handling DTDs. In comparison with tools for handling XML documents, those for handling DTDs are few, and their quality and price are not very satisfactory.

Insufficient datatypes

XML inherits DTDs from SGML, which has been used primarily for representing human-readable documents rather than representing data interchanged between programs. For this reason, the datatypes of DTDs are totally insufficient for data interchange and interwork with Java or a relational database.

For example, suppose that we want to introduce the tag name <age> to represent the age of a person. If a person is ten years old, we write <age>10</age>. However, because of the limitations of DTDs, we cannot specify that only integers are permitted. As a result, we cannot automatically detect inappropriate descriptions such as <age>unknown</age>.

Inconsistencies with namespaces

An important extension to XML 1.0 is the introduction of namespaces. Unfortunately, DTDs cannot handle namespaces properly. In particular, schema authors are forced to define namespace prefixes for namespace names (URIs); documents cannot use other namespace prefixes.

To overcome the problems of DTDs, several schema languages have been developed. In this chapter, we consider two notable languages: XML Schema of W3C and RELAX NG of OASIS and ISO/IEC JTC1. These schema languages use the XML syntax to represent schemas, and they support namespaces and datatypes.

    [ directory ] Previous Section Next Section