Datasheet
XML Technologies
As the popularity of XML grows, new technologies that complement XML’s capabilities also continue to
grow. The following section takes a quick tour of the important XML technologies that are essential to
the understanding and development of XML-based ASP.NET Web applications.
DTD
One of the greatest strengths of XML is that it allows you to create your own tag names. But for any given
application, it is probably not meaningful for any kind of tags to occur in a completely arbitrary order. If
the XML document is to have meaning, and certainly if you’re writing a style sheet or application to
process it, there must be some constraint on the sequence and nesting of tags. DTDs are one way using
which constraints can be expressed.
DTDs, often referred to as doctypes, consist of a series of declarations for elements and associated
attributes that may appear in the documents they validate. If this target document contains other ele-
ments or attributes, or uses included elements and attributes in the wrong way, validation will fail. In
effect, the DTD defines a grammar for the documents it validates.
The following shows an example of what a DTD looks like:
<?xml version=”1.0” ?>
<!-- DTD is not parsed as XML, but read by parser for validation -->
<!DOCTYPE book [
<!ELEMENT book (title, chapter+)>
<!ATTLIST book author CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT chapter (#PCDATA)>
<!ATTLIST chapter id #REQUIRED>
]>
From the preceding DTD, you can already recognize enough vocabulary to understand this DTD as a
definition of a book document that has elements book, title, and chapter and attributes author and id. A
DTD can exist inline (inside the XML document), or it can be externally referenced using a URL.
A DTD also includes information about data types, whether values are required, default values, number
of allowed occurrences, and nearly every other structural aspect you could imagine. At this stage, just be
aware that your XML-based applications may require an interface with these types of information if
your partners have translated documents from SGML to XML or are leveraging part of their SGML
infrastructure.
As mentioned before, DTDs may either be stored internally as part of the XML document or externally
in a separate file, accessible via a URL. A DTD is associated with an XML document by means of a
<!DOCTYPE> declaration within the document. This declaration specifies a name for the doctype (which
should be the same as the name of the root element in the XML document) along with either a URL
reference to a remote DTD file, or the DTD itself.
It is possible to reference both external and internal DTDs, in which case the internal DTD is processed
first, and duplicate definitions in the external file may cause errors. To specify an external DTD, use
either the SYSTEM or PUBLIC keyword as follows:
<!DOCTYPE docTypeName SYSTEM “http://www.wrox.com/Books.dtd”>
12
Chapter 1
04_596772 ch01.qxd 12/13/05 11:17 PM Page 12