Module 2 - Dynamic Document With Javascript - PDF
Module 2 - Dynamic Document With Javascript - PDF
Attribute(s) Description
position Specifies the type of positioning
applied to an element
top, left Specifies the position of the top and left
edges of an element
bottom, right
Specifies the position of the bottom and
right edges of an element
width, height
Specifies the size of an element
Specifies the "stacking order" of an
z-index element relative to any overlapping
elements; defines a third dimension of
element positioning
display Specifies how and whether an element
is displayed
visibility Specifies whether an element is visible
Defines a "clipping region" for an
clip element; only portions of the element
within this region are displayed
overflow Specifies what to do if an element is
bigger than the space allotted for it
The Key to DHTML: The position Attribute
Once you have set the position attribute of an element to something other
than static, you can specify the position of that element with some
combination of the left , top, right, and bottom attributes. The most common
positioning technique is to specify the left and top attributes, which specify
the distance from the left edge of the containing element (usually the
document itself ) to the left edge of the element, and the distance from the
top edge of the container to the top edge of the element. For example, to
place an element 100 pixels from the left and 100 pixels from the top of the
document, you can specify CSS styles in a style attribute as follows:
To position an element so that its top edge is 10 pixels from the top of the
window and its right edge is 10 pixels from the right of the window, you can
use these styles:
Note that the right and bottom attributes are newer additions to the CSS
standard and are not supported by fourth-generation browsers, as top and left
are.
In addition to the position of elements, CSS allows you to specify their size.
This is most commonly done by providing values for the width and height
style attributes. For example, the following HTML creates an absolutely
positioned element with no content. Its width, height, and background-color
attributes make it appear as a small blue square:
<div style="position: absolute; left: 10px; right:
10px; width: 10px; height: 10px;
background-color: blue">
</div>
Another way to specify the width of an element is to specify a value for both
the left and right attributes. Similarly, you can specify the height of an
element by specifying both top and bottom. If you specify a value for left,
right, and width, however, the width attribute overrides the right attribute; if
the height of an element is over-constrained, height takes priority over
bottom.
Bear in mind that it is not necessary to specify the size of every dynamic
element. Some elements, such as images, have an intrinsic size. Furthermore,
for dynamic elements that contain text or other flowed content, it is often
sufficient to specify the desired width of the element and allow the height to
be determined automatically by the layout of the element's content.
In the previous positioning examples, values for the position and size
attributes were specified with the suffix "px". This stands for pixels. The
CSS standard allows measurements to be done in a number of other units,
including inches ("in"), centimeters
("cm"), points ("pt"), and ems ("em" -- a measure of the line height for the
current font). Pixel units are most commonly used with DHTML
programming. Note that the CSS standard requires a unit to be specified.
Some browsers may assume pixels if you omit the unit specification, but
you should not rely on this behavior.
Instead of specifying absolute positions and sizes using the units shown
above, CSS also allows you to specify the position and size of an element as
a percentage of the size of the containing element. For example, the
following HTML creates an empty element with a black border that is half
as wide and half as high as the containing element (or the browser window)
and centered within that element:
It is important to understand some details about how the left , right, width,
top, bottom, and height attributes work. First, width and height specify the
size of an element's content area only; they do not include any additional
space required for the element's padding, border, or margins. To determine
the full onscreen size of an element with a border, you must add the left and
right padding and left and right border widths to the element width, and you
must add the top and bottom padding and top and bottom border widths to
the element's height.
Since width and height specify the element content area only, you might
think that left and top (and right and bottom) would be measured relative to
the content area of the containing element. In fact, the CSS standard specifies
that these values are measured relative to the outside edge of the containing
element's padding (which is the same as the inside edge of the element's
border).
Now that you understand that width and height specify the size of an
element's content area only and that the left, top, right, and bottom attributes
are measured relative to the containing element's padding, there is one more
detail you must be aware of: Internet Explorer Versions 4 through 5.5 for
Windows (but not IE 5 for the Mac) implement the width and height
attributes incorrectly and include an element's border and padding (but not its
margins). For example, if you set the width of an element to 100 pixels and
place a 10-pixel margin and a 5-pixel border on the left and right, the content
area of the element ends up being only 70 pixels wide in these buggy
versions of Internet Explorer.
In IE 6, the CSS position and size attributes work correctly when the browser
is in standards mode and incorrectly (but compatibly with earlier versions)
when the browser is in compatibility mode. Standards mode, and hence
correct implementation of the CSS
"box model," is triggered by the presence of a <!DOCTYPE> tag at the start
of the document, declaring that the document adheres to the HTML 4.0 (or
later) standard or some version of the XHTML standards. For example, any
of the following three HTML document type declarations cause IE 6 to
display documents in standards mode:
Netscape 6 and the Mozilla browser handle the width and height attributes
correctly. But these browsers also have standards and compatibility modes,
just as IE does. The absence of a <!DOCTYPE> declaration puts the
Netscape browser in quirks mode, in which it mimics certain (relatively
minor) nonstandard layout behaviors of Netscape 4. The presence of
<!DOCTYPE> causes the browser to break compatibility with Netscape 4
and correctly implement the standards.
Moving elements
id = window.setInterval("animate();", 100);
A rather rare, but still used, DHTML scenario is not only positioning an
element, but also moving and therefore animating an element. To do so,
window.setTimeout() and window.setInterval() come in handy. The
following code animates an ad banner diagonally over the page. The only
potential issue is how to animate the position. For the Internet Explorer
properties (posLeft, posTop), just adding a value suffices. For left and top,
you first have to determine the old position and then add a value to it. The
JavaScript function parseInt() extracts the numeric content from a string like
"123px". However, parseInt() returns NaN if no value is found in left or top.
Therefore, the following helper function takes care of this situation; in this
case, 0 is returned instead:
function
myParseInt(s) { var
ret = parseInt(s);
return (isNaN(ret) ? 0 : ret);
}
Then, the following code animates the banner and stops after 50 iterations:
Animating an Element (animate.html; excerpt)
<script
language="JavaScript"
type="text/javascript">
var nr = 0; var
id = null;
function
animate() {
nr++;
if (nr > 50) { window.clearInterval(id);
document.getElementById("element").style.visibility = "hidden";
} else {
var el =
document.getElementById("element");
el.style.left =
(myParseInt(el.style.left) + 5) +
"px"; el.style.posLeft += 5;
el.style.top =
(myParseInt(el.style.top) + 5) +
"px"; el.style.posTop += 5;
}
}
window.onload = function() {
id = window.setInterval("animate();", 100);
};
</script>
<h1>My Portal</h1>
<div id="element" style="position:
absolute; background-color: #eee;
border: 1px solid"> JavaScript
Phrasebook
</div>
Element visibility
The visibility property of an element controls whether it is displayed
- The values are visible and hidden
- Suppose we want to toggle between hidden and visible, and the
element‘s DOM address is dom
if (dom.visibility ==
"visible" dom.visibility =
"hidden";
else
dom.visibility = "visible";
--> SHOW showHide.html
Changing colors and fonts
In order to change text colors, you will need two things:
You have the ability to change full-page text colors over four levels:
<TEXT="######"> -- This denotes the full-page text color.
<LINK="######"> -- This denotes the color of the links on
your page.
<ALINK="######"> -- This denotes the color the link will flash when clicked
upon.
<VLINK="######"> -- This denotes the colors of the links after they have been
visited.
These commands come right after the <TITLE> commands. Again, in that
position they affect everything on the page. Also... place them all together
inside the same command along with any background commands. Something
like this:
<VLINK="#FFFFFF">
It's a pain in the you-know-where, but it gets the job done. It works with all
H commands and text size commands. Basically, if it's text, it will work.
Using Cascading
Style Sheets (CSS) to Change Text Colors
There isn't enough space to fully describe what CSS is capable of in this
article, but we have several articles here that can get you up to speed in no
time! For a great tutorial on using CSS to change color properties, check out
this article by Vincent Wright.
<STYLE
type=text/css>
A:link {
COLOR: red /*The color of the link*/
}
A:visited {
COLOR: #800080 /*The color of the visited link*/
}
A:hover {
COLOR: green /*The color of the mouseover or 'hover' link*/
}
BODY { COLOR: #800080 /*The color of all the other text within the body of the
page*/
{
</STYLE>
Alternately, you can include the CSS that is between the STYLE tags
above, and save it in a file that you could call "basic.css" which would be
placed in the root directory of your website. You would then refer to that
style sheet by using a link that goes between
Programming the Web 10CS73
The use of CSS is vastly superior to using inline FONT tags and such, as it
separates the content of your site from the style of your site, simplifying the
process as you create more pages or change the style of elements. If you are
using an external style sheet, you can make the change once in the style
sheet, and it will be applied to your entire site. If you choose to include the
style sheet itself within the HEAD tags as shown above, then you will have
to make those changes on every page on your site.
Dynamic content
In the early days of the Web, once a Web page was loaded into a client's
browser, changing the information displayed on the page required another
call to the Web server.
The user interacted with the Web page by submitting forms or clicking on
links to other Web pages, and the Web server delivered a new page to the
client.
Stacking Elements
The top and left properties allow the placement of an element anywhere in the two
dimensions of the display of a document. Although the display is restricted to two
physical dimensions, the effect of a third dimension is possible through the simple
concept of stacked elements, such as that used to stack windows in graphical user
interfaces. Although multiple elements can occupy the same space in the document, one
is considered to be on top and is displayed. The top element hides the parts of the lower
elements on which it is superimposed. The placement of elements in this third
dimension is controlled by the z-index attribute of the element. An element whose z-
Programming the Web 10CS73
index is greater than that of an element in the same space will be displayed over the
other element, effectively hiding the element with the smaller z-index value. The
JavaScript style property associated with the z-index attribute is zIndex.
In the next example, three images are placed on the display so that they overlap. In the
XHTML description of this situation, each image tag includes an onclick attribute,
which is used to trigger the execution of a JavaScript handler function. First the
function defines DOM addresses for the last top element and the new top element. Then
the function sets the zIndex value of the two elements so that the old top element has a
value of 0 and the new top element has the value 10,
effectively putting it at the top. The script keeps track of which image is currently on
top with the global variable top, which is changed every time a new element is moved
to the top with the toTop function. Note that the zIndex value, as is the case with other
properties, is a string. This document, called stacking.html, and the associated
JavaScript file are as follows:
XML
5.1 Introduction
SGML.
_ XML is not a replacement for HTML . Infact two have different goals
_ HTML is a markup language used to describe the layout of any kind of
information
_ XML is a meta-markup language that provides framework for defining
specialized markup languages
_ Instead of creating text file like
<html>
<head><title>name</title></head>…
… Syntax
<name>
<first> nandini </first>
<last> sidnal </last>
</name>
XML is much larger then text file but makes easier to write software that
accesses the information by giving structure to data.
_ XML is a very simple and universal way of storing and transferring any textual
kind
_ XML does not predefine any tags
- XML tag and its content, together with closing tag _ element
_ XML has no hidden specifications
_ XML based markup language as _ tag set
_ Document that uses XML based markup language _ XML document
_ An XML processor is a program that parses XML documents and provides
the parts to an application
_ Both IE7 and FX2 support basic XML XML is a meta language for
describing mark-up languages. It provides a facility to define tags and the
structural relationship between them
What is XML?
• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to carry data, not to display data
Programming the Web 10CS73
• XML tags are not predefined. You must define your own tags
• XML is designed to be self-descriptive
• XML is a W3C
Recommendation XML is not a
replacement for HTML.
• XML syntax rules:
The syntax of XML can be thought of at two distinct levels.
1. There is the general low-level syntax of XML that imposes its rules on all
XML documents.
2. The other syntactic level is specified by either document type definitions
or XML schemas. These two kinds of specifications impose structural
syntactic rules on documents written with specific XML tag sets.
_ DTDs and XML schema specify the set of tags and attributes that can
appear in particular document or collection of documents, and also the orders
and various arrangements in which they can appear.
DTD‘s and XML schema can be used to define a XML markup
language. XML document can include several different kinds
of statements.
• Data elements
• Markup declarations - instructions to XML parser
• Processing instructions – instructions for an applications program that will
process the data described in the document. The most common of these are
the data elements of the document. XML document may also include markup
declarations, which are instructions to the XML parser, and processing
instructions, which are instructions for an application program that will
process the data described in the document.
All XML document must begin with XML declaration. It identifies the
document as being XML and provides the version no. of the XML standard
being used. It will also include encoding standard. It is a first line of the
XHTML document.
<p>This is a paragraph
<p>This is another
paragraph. must have a closing tag:
<p>This is a paragraph</p>
<p>This is another
paragraph</p>
<Message>This is incorrect</message>
<message>This is correct</message>
In the example above, "Properly nested" simply means that since the
<i> element is opened inside the <b> element, it must be closed inside
the <b> element.
XML Documents Must Have a Root Element
t contain one element that is the parent of all other
elements.
This element is called the root element.
<root>
<child>
<subchild> </subchild>
</child>
</root>
XML tags can have attributes, which are specified with name/value
assignments. XML Attribute Values must be enclosed with single or double
quotation marks. XML document that strictly adheres to these syntax rule is
considered as well formed. An XML document that follows all of these rules
is well formed
Example :
<?xml version = ―1.0‖ encoding = ―utf-8‖ ?>
<ad>
<year>1960</year>
<make>Cessna</make>
<model>Centurian</moel>
<color>Yellow with white trim</color>
<location>
<city>Gulfport</city>
<state>Mississippi</state>
</location>
</ad>
None of this tag in the document is defined in XHTML-all are designed for
the specific content of the document. When designing an XML document,
the designer is often faced with the choice between adding a new attribute to
an element or defining a nested element.
Programming the Web 10CS73
Document structure
PCDATA is text that will be parsed by a parser. Tags inside the text will be
treated as markup and entities will be expanded.
CDATA
CDATA also means character data. CDATA is text that will NOT be parsed
by a parser. Tags inside the text will NOT be treated as markup and entities
will not be expanded.
Most of you know the HTML entity reference: " " that is used to
insert an extra space in an HTML document. Entities are expanded when a
document is parsed by an XML parser.
_ An XML document often uses two auxiliary files:
• One to specify the structural syntactic rules ( DTD / XML schema)
• One to provide a style specification ( CSS /XSLT Style Sheets)
Entities
An XML document has a single root element, but often consists of one or
more entities An XML document consist of one or more entities that are
logically related collection of information,
Entities range from a single special character to a book chapter
• An XML document has one document entity
* All other entities are referenced in the
document entity Reasons to break a document
into multiple entities.
1. Good to define a Large documents as a smaller no. of parts easier to manage .
2. If the same data appears in more than one place in the document, defining
it as a entity allows any no. of references to a single copy of data.
3. Many documents include information that cannot be represented as text,
such as images. Such information units are usually stored as binary data.
Binary entities can only be referenced in the document entities
Entity names:
• No length limitation
• Must begin with a letter, a dash, or a colon
• Can include letters, digits, periods, dashes, underscores, or colons
_ A reference to an entity has the form name with prepended
ampersand and appended semicolon: &entity_name; Eg. &apple_image;
Programming the Web 10CS73
• General form:
2. Declaring Attributes:
• Attributes are declared separately from the element declarations
• General form:
<!ATTLIST element_name attribute_name attribute_type [default
_value]> More than one attribute
< !ATTLIST element_name attribute_name1 attribute_type default_value_1
attribute_name 2 attribute_type default_value_2
…>
_ Attribute type :There are ten different types, but we will consider only CDATA
_ Possible Default value for attributes:
Value - value ,which is used if none is specified
#Fixed value - value ,which every element have and can‘t be changed
# Required - no default value is given ,every instance must
specify a value #Implied - no default value is given ,the value
may or may not be specified Example :
<!ATTLIST car doors CDATA "4">
<!ATTLIST car engine_type CDATA #REQUIRED>
<!ATTLIST car make CDATA #FIXED "Ford">
<!ATTLIST car price CDATA #IMPLIED>
<car doors = "2" engine_type = "V8">
...
</car>
Declaring Entities :
Two kinds:
• A general entity can be referenced anywhere in the content of an
XML document Ex: Predefined entities are all general entities.
• A parameter entity can be referenced only in DTD.
• General Form of entity declaration.
<!ENTITY [%] entity_name "entity_value">
% when present it specifies declaration
parameter entity Example :
Programming the Web 10CS73
Namespaces
ı XML provides benefits over bit formats and can now create well formed
XML doc. But when applications become complex we need to combine
elements from various doc types into one XML doc. This causes Pb?
ı Two documents will have elements with same name but with different
meanings and semantics.
ı Namespaces – a means by which you can differentiate elements and
attributes of different XML document types from each other when combining
them together into other documents , or even when processing multiple
documents simultaneously.
ı W hy do we need Namespaces?
ı XM L allows users to create their tags, naming collisions can occur For
ex: element title
– <title>Resume of John</title>
– <title>Sir</title><Fname>John</Fname>
ı Na mespaces provide a means for user to prevent naming collisions Element title
– <xhtml:title>Resume of John</xhtml:title>
ı Usually the element for which a namespace is declared is usually the root
of a document.
<html xmlns = http://www.w3.org/1999/xhtml>
This declares the default namespace, from which names appear
without prefixes. As an example of a prefixed namespace declaration,
consider
<birds xmlns:bd = http://www.audubon.org/names/species>
Within the birds element, including all of its children elements, the names
from the namespace must be prefixed with bd, as in the following.
<bd:lark>
If an element has more than one namespace declaration, then
<birds xmlns:bd =
―http://www.audubon.org/names/species‖ >
xmlns : html =
―http://www.w3.org/1999/xhtml‖ >
Here we have added the standard XHTML namespace to the birds element.
One namespace declaration in an element can be used to declare a default
namespace. This can be done by not including the prefix in the declaration.
The names from the default by omitting the prefix.
Consider the example in which two namespaces are
declared. The first is declared to be the default
namespaces.
The second defines the prefix, cap.
<states>
xmlns = http://www.states-info.org/states
xmlns:cap = http://www.states-info.org/state-capitals
<state>
<name> South Dakota </name>
<population> 75689 </population>
<capital>
Programming the Web 10CS73
XML schemas
• DTDs do not allow restriction on the form of data that can be content of
element ex:
<quantity>5</quantity> and <quantity>5</quantity> are valid DTD can
only specifies that could be anything. Eg time No datatype for integers all are
treated as texts.
ı XM L Schemas is one of the alternatives to DTD
• It is XML document, so it can be parsed with XML parser
• It also provides far more control over data types than do DTDs
• User can define new types with constraints on existing data types
1. Schema Fundamentals:
• These are given as attribute assignments in the tag for its root element
<planes
xmlns = http://cs.uccs.edu/planesScema
…>
2. It is root element of an instance document is for the schemaLocation attribute.
• Use the element tag and set the name and type attributes
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name = ―phoneNumber" >
<xsd:restriction base = "xsd:decimal" >
<xsd:precision value = ―10" />
</xsd:restriction>
</xsd:simpleType>
6. Declaring Complex Types:
• There are several categories of complex types, but we discuss just one,
element-only elements
• Element-only elements are defined with the complex Type element
• Use the sequence tag for nested elements that must be in a particular order
• Nested elements can include attributes that give the allowed number of
occurrences (minOccurs, maxOccurs, unbounded)
• For ex:
ı An XML enabled browser or any other system that can deal with XML
documents cannot possibly know how to format the tags defined in the doc.
ı Without a style sheet that defines presentation styles for the doc tags the
XML doc can not be displayed in a formatted manner.
Programming the Web 10CS73
ı Some browsers like FX2 have default style sheets that are used when style
sheets are not defined.
ı Eg of planes.xml document.
ı Using CSS is effective, XSLT provides far more power over the
appearance of the documents display.
ı A C SS style sheet for an XML document is just a list of its tags and associated
styles
ı The connection of an XML document and its style sheet is made
through an xmlstylesheet processing instruction
ı Display– used to specify whether an element is to be displayed inline or in
a separate block.
<?xml-stylesheet type = "text/css― herf =
―planes.css"?> For example: planes.css
<!-- planes.css - a style sheet for the planes.xml
document --> ad { display: block; margin-top: 15px;
color: blue;}
year, make, model { color: red; font-size: 16pt;}
color {display: block; margin-left: 20px; font-size:
12pt;} description {display: block; margin-left: 20px;
font-size: 12pt;} seller { display: block; margin-left:
15px; font-size: 14pt;} location {display: block;
margin-left: 40px; }
city {font-size:
12pt;} state {font-
size: 12pt;}
<?xml version = "1.0" encoding = "utf-8"?>
Programming the Web 10CS73
<!-- planes.xml - A document that lists ads for used airplanes -->
<planes_for_sale>
<ad>
<year> 1977 </year>
<make> Cessana </make>
<model> Skyhawk </model>
<color> Light blue and white </color>
<description> New interior
</description>
<seller phone = "555-222-
3333"> Skyway Aircraft
</seller>
<location>
<city> Rapid City, </city>
<state> South Dakota </state>
</location>
</ad>
</planes_for_sale>
With planes.css the display of planes.xml as following: 1977 Cessana
Skyhawk Light blue and white New interior Skyway Aircraft Rapid City,
South Dakota
Web Services:
ı The ultimate goal of Web services: Allow different software in different
places, written in different languages and resident on different platforms, to
connect and interoperate
ı The Web began as provider of markup documents, served through the HTTP
methods,
Programming the Web 10CS73
- The same Web server can provide both documents and services
ı The original Web services were provided via Remote Procedure Call
(RPC), through two technologies, DCOM and CORBA. DCOM and
CORBA use different protocols, which defeats the goal of universal
component interoperability
ı The re are three roles required to provide and use Web services:
1. Service providers
2. Service requestors
3. A service registry
• Service providers
• Service requestors
• Service registry
An XSLT document consists primarily of one or more templates, which use XPath
to describe element–attribute patterns in the input XML document. Each template
has associated with it a section of XSLT “code,” which is “executed” when a
match to the template is found in the XML document. So, each template
describes a function that is executed whenever the XSLT processor finds a match
to the template’s pattern.
An XSLT processor sequentially examines the input XML document, searching for
parts that match one of the templates in the XSLT document. XML documents
consist of nodes—elements, attributes, comments, text, and processing
instructions. If a template matches an element, the element is not processed until
the
closing tag is found. When a template matches an element, the child elements of
that element may or may not be processed.
One XSLT model of processing XML data is called the template-driven model,
which works well when the data consists of multiple instances of highly regular
Programming the Web 10CS73
data collections, as with files containing records. XSLT can also deal with irregular
and recursive data, using template fragments in what is called the data-driven
model. A single XSLT style sheet can include the mechanisms for both the
template- and data-driven models. The discussion of XSLT in this chapter is
restricted to the template-driven model.
To keep the complexity of the discussion manageable, the focus is on
transformations that are related to presentation. The examples in this section were
processed with the XSLT processor that is part of IE8.
XML Processors
So far in this chapter, we have discussed the structure of XML documents, the
rules for writing them, the DTD and XML Schema approaches to specifying the
particular tag sets and structure of collections of XML documents, and the CSS
and XSLT methods of displaying the contents of XML documents. That is
tantamount to telling a long story about how data can be stored and displayed,
without providing any hint on how it may be processed. Although we do not
discuss processing data stored in XML documents in this section, we do introduce
approaches to making that data conveniently available to application programs that
process the data.
was recognized early on that, because the process of the initial syntactic analysis
required to expose the embedded data must be repeated for every application that
processes XML documents, standard syntax analyzers for XML documents were
needed. Actually, the syntax analyzers themselves need not be standard; rather,
they should expose the data of XML documents in a standard application
programmer interface (API). This need led to the development of two different
standard APIs for
XML processors. Because there are different needs and uses of XML applications,
having two standards is not a negative. The two APIs parallel the two kinds of
output that are produced by the syntax analyzers of compilers for programming
languages. Some of these syntax analyzers produce a stream of the syntactic
structures
of an input program. Others produce a parse tree of the input program that shows
the hierarchical structure of the program in terms of its syntactic structures.
The DOM representation of an XML document has several advantages over the
sequential listing provided by SAX parsers. First, it has an obvious advantage if
any part of the document must be accessed more than once by the application.
Second, if the application must perform any rearrangement of the elements of the
document, that can most easily be done if the whole document is accessible at the
same time. Third, accesses to random parts of the document are possible.
Finally, because the parser sees the whole document before any processing takes
place, this approach avoids any processing of a document that is later found to be
invalid (according to a DTD or XML schema).
In some situations, the SAX approach has advantages over the DOM method. The
DOM structure is stored entirely in memory, so large documents require a great
deal of memory. In fact, because there is no limit on the size of an XML document,
some documents cannot be parsed with the DOM method. This is not a problem
with the SAX approach. Another advantage of the SAX method is speed: It is
faster than the DOM approach.
The process of building the DOM structure of an XML document requires some
syntactic analysis of the document, similar to that done by SAX parsers. In fact,
most DOM parsers include a SAX parser as a front end.