- 100 -
10:
Chapter 4:
Introduction to Document Object
Model (DOM)
Overview
XML was introduced to alleviate interoperability problems across platforms and networks.
A standard language, combined with a DTD (or another schema construct), provides a
standard data way of exchanging data. Not only does data need to be in a standard
format, but the way data is accessed should also be standardized. XML provides the
constructs for putting
data into a standard format, and as we shall soon see, the
Document Object Model provides a standard way of accessing data. A Web developer,
who provides some script inside a Web page that makes use of an XML document,
shouldn’t have to recode the script to work in every browser.
Some overhead is involved when
using XML documents, because extracting data from the
tags in an XML document can be arduous. A parser is used to take care of checking a
document’s validity and extracting the data from the XML syntax. A layer of abstraction
between the application and the XML document is made possible by
the XML Document
Object Model (DOM) specification, which has been standardized by the W3C. This layer of
abstraction comes in the form of interfaces that have methods and properties to manipulate
an XML document.
In other words, when using the DOM, you don’t need to worry about the
XML syntax directly. For example,
the methods, getAttribute(...) and setAttribute(...), allow
you to manipulate the attributes on an element in an elegant fashion. Legacy systems can
use these interfaces to provide access to legacy data as if the data was natively stored in
XML. In other words, your legacy data can be made to look
like an XML document by
implementing the DOM interfaces on top of the legacy database.