XML Document Type Definition




Download 2,96 Mb.
Pdf ko'rish
bet56/131
Sana14.05.2024
Hajmi2,96 Mb.
#232039
1   ...   52   53   54   55   56   57   58   59   ...   131
Bog'liq
Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

XML Document Type Definition
Often, it is desirable to have information structured in a particular way. For example, you 
may want an address in an address book to include a ZIP code or a bibliography to 
include the name of the publisher. To insure that information is structured properly, you 
can create a set of rules for your XML documents through Document Type Definitions
 
(DTDs.) DTDs are a series of expressions that define the logical structure of your XML 
document. The DTD is an optional part of your XML system. By and large, though, for 
any serious application, you would want to include a DTD, especially in instances where 
you are gathering information from a customer, for example, while gathering name 
information in a form submission. A name can consist of a first name and a last name. 
Identifying a person on the basis of the last name becomes more difficult when both the 
first and last names are put together, so often they are represented by two fields. By 
explicitly declaring that a name must consist of two parts, the parser is able to perform 
error checking for you so you don’t have to write your own code to insure that the user 
has put in the right information.
In 
Chapter 1
, we talked a little about DTDs and how we don’t particularly care for them. 
Nevertheless, they are the only officially recommended way for creating rules in XML 
documents; thus we spend some time going over how to create an XML DTD in this 
chapter.
XML Parser
An XML parser is a software engine that checks your XML document to insure that it is 
syntactically correct. If you have chosen to include a DTD, the XML parser also checks 
your XML document against the DTD to insure that it is also structured correctly.
A parser reads the XML document’s information and makes it accessible to the XML 
application. All parsers are supposed to behave the same but the reality is that they don’t. 
Most of them have their own quirks and nuances (also known as features). For the most 
part, this book uses the parsers included with Microsoft’s Internet Explorer 5 and 
Netscape Navigator 5 (alpha). A list of easily available parsers is included in 
Appendix B
.
Choosing which parser to use is important and a lot depends on the language in which 
you are writing your application. Some parsers are written for C++, while others are 
written in Java. We talk a lot about interfacing with parsers through code in 
Download 2,96 Mb.
1   ...   52   53   54   55   56   57   58   59   ...   131




Download 2,96 Mb.
Pdf ko'rish