Module 4
1 Introducing XML
What is XML?
XML stands for eXtensible Markup Language. It is a markup language much like HTML, but
there are several differences between them:
• HTML includes a collection of predefined tags that you can use right away in editing your
HTML files, e.g. <font> and <h1>, but XML tags are not predefined.
To use XML, users have to define their own tags for their specific application before using
them. For example, to describe a note, <note>, <to>, <from>, <heading>, and <body> are
defined in advance and used in a nested fashion to present the following XML file as a
note:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget the party!</body>
</note>
With XML, one can define whatever tags needed, which together compose a user-defined
markup language similar to HTML, and then use the language to describe data. Specif-
ically XML uses Document Type Definition (DTD) or an XML Schema to define tags. In this
sense, XML is viewed as a meta-language since it can be used to define and de- scribe a
markup language instead of concrete data directly. That is also why it is called extensible.
• XML was designed to describe data while HTML was designed for displaying data.
If you remember, HTML tags control the way data is presented to browser users, color,
font size, spacing, etc. Differently XML aims to deal with the logic meaning of data, or
semantics. In the above example, the text wrapped in <from> and </from> is the name
This note is created based on the XML tutorial on [Link]
1
1
of the sender of the note. This enables the fulfillment of the task of finding all the notes
written by a specific person. So XML was designed to describe data and to focus on what
data is while HTML was designed to display data and to focus on how data looks.
Actually XML and HTML can complement each other. For example, we use XML files to
store data on a web server machine and when a request arrives, a servlet runs to retrieve
data in XML, compose a HTML file, and finally output it to the client. This way you can
concentrate on using HTML for data layout and display, and be sure that changes in the
underlying data will not require any changes to your HTML.
Besides XML’s role of storing data, with XML, data can be exchanged between incom-
patible systems.
In the real world, computer systems and databases contain data in incompatible formats.
One of the most time-consuming challenges for developers has been to exchange data
between such systems over the Internet.
Converting the data to XML can greatly reduce this complexity and create data that can
be read by many different types of applications, since XML data is stored in plain text
format, which is software- and hardware-independent.
The best description of XML may be this: XML is a cross-platform, software and hardware
independent tool for transmitting information. Since the creation of XML, it has been amazing
to see how quickly the XML standard has been developed and how quickly a large number of
software vendors have adopted the standard. It is strongly believed by the IT community at
large that XML will be as important to the future of the Web as HTML has been to the
foundation of the Web and that XML will be the most common tool for all data manipulation
and data transmission.
XML Syntax
The syntax rules of XML are very simple and very strict. The rules are very easy to learn, and
very easy to use. Because of this, creating software that can read and manipulate XML is very
easy to do.
An Example XML Document
XML documents use a self-describing and simple syntax. For example, the following is a
complete XML file presenting a note:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
2
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>
The first line in the document – the XML declaration – defines the XML version and the
character encoding used in the document. In this case the document conforms to the 1.0
specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set.
The next line and the last line describe the root element of the document (like it was saying:
“this document is a note”). So when you look at the document, you easily detect this is a note to
Tove from Jani. So XML is pretty self-descriptive.
Rigid Syntax
Different from HTML, XML has a syntax that is much more rigid.
• With XML, it is illegal to omit the closing tag.
In HTML some elements do not have to have a closing tag to be able to present content in
the way the user wants them to. For example:
<p>This is a paragraph
<p>This is another paragraph
In XML, however, all elements must have a closing tag, like this:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Note that you might have noticed from the previous example that the XML declaration
did not have a closing tag. This is not an error. The declaration is not a part of the XML
document itself. It is not an XML element, and it should not have a closing tag.
• Unlike HTML, XML tags are case sensitive.
With XML, the tag <Letter> is different from the tag <letter>. Opening
and closing tags must therefore be written with the same case:
<Message>This is incorrect</message>
<message>This is correct</message>
• Improper nesting of tags makes no sense to XML.
In HTML some elements can be improperly nested within each other and still display
content in the desired way like this:
3
<b><i>This text is bold and italic</b></i>
In XML all elements must be properly nested within each other like this:
<b><i>This text is bold and italic</i></b>
• All XML documents must contain a single tag pair to define a root element.
All other elements must be within this root element. All elements can have sub elements
(child elements). Sub elements must be correctly nested within their parent element:
<root>
<child>
<subchild>. </subchild>
</child>
</root>
• With XML, it is illegal to omit quotation marks around attribute values.
XML elements can have attributes in name/value pairs just like in HTML. In XML the
attribute value must always be quoted. Study the two XML documents below. The first
one is incorrect, the second is correct:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note date=12/11/2002>
<to>Tove</to>
<from>Jani</from>
</note>
<?xml version="1.0" encoding="ISO-8859-1"?>
<note date="12/11/2002">
<to>Tove</to>
<from>Jani</from>
</note>
The error in the first document is that the date attribute in the note element is not
quoted.
• With XML, the white space in your document is not truncated.
This is unlike HTML. With HTML, a sentence like this:
Hello my name is Tove,
will be displayed like this:
4
Hello my name is Tove,
because HTML strips off the white space.
• With XML, CR/LF is converted to LF.
Do you know what a typewriter is? Well, a typewriter is a mechanical device used in the
previous century to produce printed documents. :-)
After you have typed one line of text on a typewriter, you have to manually return the
printing carriage to the left margin position and manually feed the paper up one line.
In Windows applications, a new line is normally stored as a pair of characters: carriage
return (CR) and line feed (LF). The character pair bears some resemblance to the type-
writer actions of setting a new line. In Unix applications, a new line is normally stored as
a LF character. Macintosh applications use only a CR character to store a new line.
• Comments in XML The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->
However as you see, there is nothing special about XML. It is just plain text with the addition of
some XML tags enclosed in angle brackets.
Software that can handle plain text can also handle XML. In a simple text editor, the XML tags
will be visible and will not be handled specially.
In an XML-aware application, however, the XML tags can be handled specially. The tags may or
may not be visible, or have a functional meaning, depending on the nature of the application.
XML Elements
XML elements define the framework of an XML document and the structure of data items.
XML Elements are Extensible
XML was invented to be extensible and XML documents can be extended to carry more
information.
Take the above note as an example again. Let’s imagine that we created an application that
extracted the <to>, <from>, and <body> elements from the XML document to produce this
output:
5
MESSAGE
To: Tove
From: Jani
Don’t forget me this weekend!
Imagine that the author of the XML document added some extra information to it:
<note>
<date>2002-08-01</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>
Should the application break or crash? No. The application should still be able to find the
<to>, <from>, and <body> elements in the XML document and produce the same output. XML
documents are Extensible.
Element Naming
XML elements must follow these naming rules:
• Names can contain letters, numbers, and other characters
• Names must not start with a number or punctuation character
• Names must not start with the letters xml (or XML or Xml ..)
• Names cannot contain spaces
Take care when you “invent” element names and follow these simple rules:
Any name can be used, no words are reserved, but the idea is to make names descriptive.
Names with an underscore separator are nice, for example <first name> and <last name>.
Avoid “-” and “.” in names. For example, if you name something “first-name,” it could be a mess
if your software tries to subtract name from first. Or if you name something “[Link],” your
software may think that “name” is a property of the object ”first.”
Element names can be as long as you like, but don’t exaggerate. Names should be short and
simple, like this: <book title> not like this: <the title of the book>.
XML documents often have a corresponding database, in which fields exist corresponding to
elements in the XML document. A good practice is to use the naming rules of your database for
6
the elements in the XML documents.
Non-English letters like o˙¸c are perfectly legal in XML element names, but watch out for
problems if your software vendor doesn’t support them.
The “:” should not be used in element names because it is reserved to be used for something
called namespaces.
XML Attributes
XML elements can have attributes in the start tag, just like HTML. Attributes are used to
provide additional information about elements.
From HTML you will remember this: <IMG SRC="[Link]">. The SRC attribute provides
additional information about the IMG element.
In HTML (and in XML) attributes provide additional information about elements:
<img src="[Link]">
<a href="[Link]">
Attributes often provide information that is not a part of the data. In the example below, the file
type is irrelevant to the data, but important to the software that wants to manipulate the
element:
<file type="gif">[Link]</file>
As we said before, attribute values in XML must always be enclosed in quotes, but either single
or double quotes can be used. Note that if the attribute value itself contains double quotes it is
necessary to use single quotes and vice versa, like in this example:
<gangster name=’George "Shotgun" Ziegler’>
Sometimes information may be placed as attributes or child elements. Take a look at these
examples:
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
and
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
In the first example sex is an attribute. In the last, sex is a child element. Both examples provide
the same information.
7
There are no rules about when to use attributes, and when to use child elements. Generally
attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if
the information feels like data.
Here are some of the problems using attributes:
• attributes cannot contain multiple values (child elements can)
• attributes are not easily expandable (for future changes)
• attributes cannot describe structures (child elements can)
• attributes are more difficult to manipulate by program code
• attribute values are not easy to test against a Document Type Definition (DTD) - which is
used to define the legal elements of an XML document
If you use attributes as containers for data, you end up with documents that are difficult to
read and maintain. Try to use elements to describe data. Use attributes only to provide
information that is not relevant to the data.
Don’t end up like this ( if you think this looks like XML, you have not understood the point):
<note day="12" month="11" year="2002" to="Tove" from="Jani" heading="Reminder" body="Don’t forget me
this weekend!"> </note>
8
XML Namespaces
XML Namespaces provide a method to avoid element name conflicts.
Name Conflicts
In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML
applications.
This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different
content and meaning.
A user or an XML application will not know how to handle these differences.
Solving the Name Conflict Using a Prefix
Name conflicts in XML can easily be avoided using a name prefix.
This XML carries information about an HTML table, and a piece of furniture:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
In the example above, there will be no conflict because the two <table> elements have different names.
XML Namespaces - The xmlns Attribute
When using prefixes in XML, a namespace for the prefix must be defined.
The namespace can be defined by an xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".
<root>
<h:table xmlns:h="[Link]
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="[Link]
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
In the example above:
The xmlns attribute in the first <table> element gives the h: prefix a qualified namespace.
The xmlns attribute in the second <table> element gives the f: prefix a qualified namespace.
When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.
Namespaces can also be declared in the XML root element:
<root xmlns:h="[Link]
xmlns:f="[Link]
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
Note: The namespace URI is not used by the parser to look up information.
The purpose of using an URI is to give the namespace a unique name.
However, companies often use the namespace as a pointer to a web page containing namespace information.
Uniform Resource Identifier (URI)
A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource.
The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. Another, not so common type of URI is
the Uniform Resource Name (URN).
Default Namespaces
Defining a default namespace for an element saves us from using prefixes in all the child elements. It has the following syntax:
xmlns="namespaceURI"
This XML carries HTML table information:
<table xmlns="[Link]
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a piece of furniture:
<table xmlns="[Link]
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
XML Schema
● A more powerful way of defining the structure and constraining the contents of XML documents
● An XML Schema definition is itself an XML document
o Typically stored as a standalone .xsd file
o XML (data) documents refer to external .xsd files
● W3C recommendation
o Unlike DTD, XML Schema is separate from the XML specification
XML Schema definition (XSD)
<?xml version="1.0"?>
<xs:schema xmlns:xs="[Link]
…… Defines xs to be the namespace
described in the URL
Uses of xs: within the xs:schema element now refer to tags from this
namespace
……
</xs:schema>
XSD example
<xs:element name="book"> We are now defining an element named book
<xs:complexType>Declares a structure with child elements/attributes as opposed to just text)
<xs:sequence>Declares a sequence of child elements, like “(…, …, …)” in DTD
<xs:element name="title" type="xs:string"/> A leaf element with string content
<xs:element name="author" type="xs:string"
Like author* in DTD
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="publisher" maxOccurs="1"/>
type="xs:string"
minOccurs="0" Like publisher? in DTD
<xs:element name="year" maxOccurs="1"/>
type="xs:integer"
minOccurs="0" A leaf element with integer content
<xs:element ref="section" Like section* in DTD; section is defined elsewhere
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="ISBN" type="xs:string" use="required"/>
Declares an attribute under book… and this attribute is required
<xs:attribute name="price" type="xs:decimal" use="optional"/> This attribute has a decimal value,
and it is optional
</xs:complexType>
</xs:element>
Viewing XML Files
To view an XML document in IE 5.0 (and higher) you can click on a link, type the URL in the
address bar, or double-click on the name of an XML file in a files folder. If you open an XML
document in IE, it will display the document with color coded root and child elements. A plus
(+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the element
structure. If you want to view the raw XML source, you must select ”View Source” from the
browser menu.
To view an XML document in Netscape 6, you’ll have to open the XML file and then right-click
in XML file and select “View Page Source”. If you open an XML document in Netscape 6, it will
display the document with color coded root and child elements.
If an erroneous XML file is opened, the browser will report the error.
Since XML tags are “invented” by the author of the XML document, browsers do not know if a
tag like <table> describes an HTML table or a dining table.
Without any information about how to display the data, most browsers will just display the
XML document as it is. In the next section, we will take a look at different solutions to the
display problem, using CSS and XSL.
Displaying XML with CSS
Before we have learned that CSS files may work together with HTML files in the way that the
former is in charge of display and the latter provides concrete information. CSS can do the
same thing with XML.
1
Below is a fraction of the XML file, with an added CSS style sheet reference. The second line,
<?xml-stylesheet type="text/css" href="cd [Link]"?>, links the XML file to the CSS file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
.
.
.
.
</CATALOG>
The CSS file cd [Link] goes as follows:
CATALOG {
background-color: #ffffff; width: 100%;
}
CD {
display: block; margin-
bottom: 30pt; margin-
left: 0;
}
TITLE {
color: #FF0000;
font-size: 20pt;
}
ARTIST {
color: #0000FF;
font-size: 20pt;
1
}
COUNTRY,PRICE,YEAR,COMPANY {
display: block; color:
#000000; margin-left:
20pt;
}
where it is specified how to display each kind of elements.
Displaying XML with XSL
Besides CSS, XSL was invented just for displaying XML. The eXtensible Stylesheet Language
(XSL) is far more sophisticated than CSS.
XSL consists of three parts:
• XSLT (XSL Transformations) is a language for transforming XML documents.
XSLT is the most important part of the XSL Standards. It is the part of XSL that is used to
transform an XML document into another XML document, or another type of document
that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by
transforming each XML element into an (X)HTML element.
XSLT can also add new elements into the output file, or remove elements. It can
rearrange and sort elements, and test and make decisions about which elements to
display, and a lot more.
A common way to describe the transformation process is to say that XSLT transforms an
XML source tree into an XML result tree.
XSLT uses XPath to define the matching patterns for transformations. In the transfor-
mation process, XSLT uses XPath to define parts of the source document that match one
or more predefined templates. When a match is found, XSLT will transform the matching
part of the source document into the result document. The parts of the source document
that do not match a template will end up unmodified in the result document.
• XPath is a language for defining parts of an XML document.
XPath uses path expressions to identify nodes in an XML document. These path expres-
sions look very much like the expressions you see when you work with a computer file
system:
w3schools/xpath/[Link]
Look at the following simple XML document:
1
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
</catalog>
The XPath expression below selects the ROOT element catalog:
/catalog
The XPath expression below selects all the cd elements of the catalog element:
/catalog/cd
The XPath expression below selects all the price elements of all the cd elements of the
catalog element:
/catalog/cd/price
Note: If the path starts with a slash (‘/’) it represents an absolute path to an element!
XPath also defines a library of standard functions for working with strings, numbers and
Boolean expressions. The XPath expression below selects all the cd elements that have a
price element with a value larger than 10.80:
/catalog/cd[price>10.80]
XML Applications
XML has a variety of uses for Web, e-business, and portable applications.
The following are some of the many applications for which XML is useful:
● Web publishing: XML allows you to create interactive pages, allows
the customer to customize those pages, and makes creating e-
commerce applications more intuitive. With XML, you store the data
1
once and then render that content for different viewers or devices
based on style sheet processing using an Extensible Style Language
(XSL)/XSL Transformation (XSLT) processor.
● Web searching and automating Web tasks: XML defines the type of
information contained in a document, making it easier to return useful
results when searching the Web:
For example, using HTML to search for books authored by Tom Brown is
likely to return instances of the term 'brown' outside of the context of
author. Using XML restricts the search to the correct context (for
example, the information contained in the <author> tag) and returns
only the information that you want. By using XML, Web agents and
robots (programs that automate Web searches or other tasks) are more
efficient and produce more useful results.
● General applications: XML provides a standard method to access
information, making it easier for applications and devices of all kinds to
use, store, transmit, and display data.
● e-business applications: XML implementations make electronic data
interchange (EDI) more accessible for information interchange,
business-to-business transactions, and business-to-consumer
transactions.
● Metadata applications: XML makes it easier to express metadata in a
portable, reusable format.
● Pervasive computing: XML provides portable and structured
information types for display on pervasive (wireless) computing devices
such as personal digital assistants (PDAs), cellular phones, and others.
For example, WML (Wireless Markup Language) and VoiceXML are
currently evolving standards for describing visual and speech-driven
wireless device interfaces.
1
DHTML
● Dynamic HTML
● Not a language, but it is a web standard
● Web page------🡪 dynamic / interactive
● Components of DHTML
o HTML
o CSS
o Javascript
o DOM
● DHTML is a TERM used to describe the technologies used to make web
pages dynamic and interactive.
● DHTML refers to web content that changes each time it is viewed. For
example, the graphic can move from one location to another, in response to a
user action, such as a mouse click.
● Enable a web page to react to user input without sending a request to a web
server.
● Used to describe the combination of HTML, style sheets, and scripts that
allow documents to be animate.
Key Features: Following are the some major key features of DHTML:
● Tags and their properties can be changed using DHTML.
1
● It is used for real-time positioning.
● Dynamic fonts can be generated using DHTML.
● It is also used for data binding.
● It makes a webpage dynamic and be used to create animations, games,
applications along with providing new ways of navigating through websites.
● The functionality of a webpage is enhanced due to the usage of low-bandwidth
effect by DHTML.
● DHTML also facilitates the use of methods, events, properties, and codes.
Components of DHTML
DHTML is used to create interactive and animated web pages that are generated
in real-time, also known as dynamic web pages so that when such a page is
accessed, the code within the page is analyzed on the web server and the
resulting HTML is sent to the client’s web browser. Following are the components
of DHTML:
HTML: HTML stands for Hypertext Markup Language and it is a client-side
markup language. It is used to build the block of web pages.
Javascript: It is a Client-side Scripting language. Javascript is supported by most
of the browser, also have cookies collection to determine the user needs.
CSS: The abbreviation of CSS is Cascading Style Sheet. It helps in the styling of
the web pages and helps in designing of the pages. The CSS rules for DHTML will
be modified at different levels using JS with event handlers which adds a
significant amount of dynamism with very little code.
DOM: It is known as a Document Object Model which act as the weakest links in
it. The only defect in it is that most of the browser does not support DOM. It is a
way to manipulate the static contents.
2
DHTML is not a technology; rather, it is the combination of three different
technologies, client-side scripting (JavaScript or VBScript), cascading style
sheets and document object model.
Advantages:
● Size of the files are compact in compared to other interactional media like
Flash or Shockwave, and it downloads faster.
● It is supported by big browser manufacturers like Microsoft and Netscape.
● Highly flexible and easy to make changes.
● Viewer requires no extra plug-ins for browsing through the webpage that uses
DHTML, they do not need any extra requirements or special software to view it.
● User time is saved by sending less number of requests to the server. As it is
possible to modify and replace elements even after a page is loaded, it is not
required to create separate pages for changing styles which in turn saves time
in building pages and also reduces the number of requests that are sent to the
server.
● It has more advanced functionality than a static HTML. it is capable of holding
more content on the web page at the same time.
2
Disadvantages:
● It is not supported by all the browsers. It is supported only by recent browsers
such as Netscape 6, IE 5.5, and Opera 5 like browsers.
● Learning of DHTML requires a lot of pre-requisites languages such as HTML,
CSS, JS, etc should be known to the designer before starting with DHTML
which is a long and time-consuming in itself.
● Implementation of different browsers are different. So if it worked in one
browser, it might not necessarily work the same way in another browser.
● Even after being great with functionality, DHTML requires a few tools and
utilities that are some expensive. For example, the DHTML text editor,
Dreamweaver. Along with it the improvement cost of transferring from HTML to
DHTML makes cost rise much higher.
Difference between HTML and DHTML:
● HTML is a markup language while DHTML is a collection of technologies.
● HTML is used to create static webpages while DHTML is capable of creating
dynamic webpages.
● DHTML is used to create animations and dynamic menus but HTML not used.
● HTML sites are slow upon client-side technologies whereas DHTML sites are
comparatively faster.
● Web pages created using HTML are rather simple and have no styling as it
uses only one language whereas DHTML uses HTML, CSS, and Javascript
which results in a much better and way more presentable webpage.
● HTML cannot be used as server side code but DHTML used as server side
code.
● DHTML needs database connectivity but not in case of HTML.
● Files in HTML are stored using .htm or .html extension while DHTML
uses .dhtm extension.
2
● HTML requires no processing from the browser but DHTML does.
DHTML Javascript
HTML document include JavaScript:: The JavaScript document is included in
our html page using the html tag. <src> tag is used to specify the source of
external JavaScript file. Following are some of the tasks that can be performed
with JavaScript:
● Performing html tasks
● Performing CSS tasks
● Handling events
● Validating inputs
Example 1: Example to understand how to use JavaScript in DHTML.
<h1>
GeeksforGeeks
</h1>
<p id = "geeks">
Hello Geeks!
</p>
<script>
[Link]("geeks").innerHTML =
"A computer science portal for geeks";
</script>
2
2