You are on page 1of 10

WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

Module - II
What is XML?

XML stands for EXtensible Markup Language


XML is a markup language much like HTML.
XML was designed to describe data.
XML tags are not predefined in XML. You must define your own tags.
XML is self describing.
XML uses a DTD (Document Type Definition) to formally describe the data.

The main difference between XML and HTML

XML is not a replacement for HTML. XML and HTML were designed with different goals:
XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus
on how data looks.
HTML is about displaying information, XML is about describing information. XML is extensible
The tags used to markup HTML documents and the structure of HTML documents are predefined. The author of
HTML documents can only use tags that are defined in the HTML standard.
XML allows the author to define his own tags and his own document structure. XML is a complement to HTML
It is important to understand that XML is not a replacement for HTML. In the future development of the Web it is
most likely that XML will be used to structure and describe the Web data, while HTML will be used to format and
display the same data.

XML in future Web development


We have been participating in XML development since its creation. 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.

We strongly believe that XML will be as important to the future of the Web as HTML has been to the foundation of
the Web. XML is the future for all data transmission and data manipulation over the Web.

XML can keep data separated from your HTML


XML can be used to store data inside HTML documents
XML can be used as a format to exchange information
XML can be used to store data in files or in databases

XML can keep data separated from your HTML

HTML pages are used to display data. Data is often stored inside HTML pages. With XML this data can now be
stored in a separate XML file. This way you can concentrate on using HTML for formatting and display, and be sure
that changes in the underlying data will not force changes to any of your HTML code.
XML can also store data inside HTML documents

XML data can also be stored inside HTML pages as "Data Islands". You can still concentrate on using HTML for
formatting and displaying the data.
XML can be used to exchange data

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 different types of
applications.
XML can be used to store data

XML can also be used to store data in files or in databases. Applications can be written to store and retrieve
information from the store, and generic applications can be used to display the data.

An example XML document:

<?xml version="1.0"?>
<note>
<to>Tove</to>

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 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 should always be included. It defines the XML version of the
document. In this case the document conforms to the 1.0 specification of XML:

<?xml version="1.0"?>

The next line defines the first element of the document (the root element):

<note>

The next lines defines 4 child elements of the root (to, from, heading, and body):

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>

The last line defines the end of the root element:

</note>

All XML elements must have a closing tag


In HTML some elements do not have to have a closing tag. The following code is legal in HTML:

<p>This is a paragraph
<p>This is another paragraph

In XML all elements must have a closing tag like this:

<p>This is a paragraph</p>
<p>This is another paragraph</p>

XML tags are case sensitive


XML tags are case sensitive. 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>

All XML elements must be properly nested


In HTML some elements can be improperly nested within each other like this:
<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 have a root tag

All XML documents must contain a single tag pair to define the root element. All other elements must be nested
within the root element. All elements can have sub (children) elements. Sub elements must be in pairs and correctly
nested within their parent element:

<root>
<child>

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

<subchild>
</subchild>
</child>
</root>

Attribute values must always be quoted

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"?>
<note date=12/11/99>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

<?xml version="1.0"?>
<note date="12/11/99">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

XML Attributes
XML attributes are normally used to describe XML elements, or to provide additional information about elements.
From HTML you can remember this construct: <IMG SRC="computer.gif">. In this HTML example SRC is an
attribute to the IMG element. The SRC attribute provides additional information about the element.
Attributes are always contained within the start tag of an element. Here are some examples:

HTML examples:
<img src="computer.gif">
<a href="demo.asp">

XML examples:

<file type="gif">
<person id="3344">

Usually, or most common, attributes are used to provide information that is not a part of the content of the XML
document. Did you understand that? Here is another way to express that: Often attribute data is more important to
the XML parser than to the reader. Did you understand it now? Anyway, in the example above, the person id is a
counter value that is irrelevant to the reader, but important to software that wants to manipulate the person element.
Use of Elements vs. Attributes

Take a look at these examples:

Using an Attribute for sex:

<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>

Using an Element for sex:

<person>

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>

In the first example sex is an attribute. In the last example sex is an element. Both examples provides the same
information to the reader.

There are no fixed rules about when to use attributes to describe data, and when to use elements. My experience is
however; that attributes are handy in HTML, but in XML you should try to avoid them, as long as the same
information can be expressed using elements.

Here is another example, demonstrating how elements can be used instead of attributes. The following three XML
documents contain exactly the same information. A date attribute is used in the first, a date element is used in the
second, and an expanded date element is used in the third:

<?xml version="1.0"?>
<note date="12/11/99">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

<?xml version="1.0"?>
<note>
<date>12/11/99</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

<?xml version="1.0"?>
<note>
<date>
<day>12</day>
<month>11</month>
<year>99</year>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Avoid using attributes? (I say yes!)

Why should you avoid using attributes? Should you just take my word for it? These are some of the problems using
attributes:

attributes can not contain multiple values (elements can)


attributes are not expandable (for future changes)
attributes can not describe structures (like child elements can)
attributes are more difficult to manipulate by program code
attribute values are not easy to test against a DTD

If you start using attributes as containers for XML data, you might end up with documents that are both difficult to
maintain and to manipulate. What I'm trying to say is that you should use elements to describe your data. Use
attributes only to provide information that is not relevant to the reader. Please don't end up like this:

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

<?xml version="1.0"?>
<note day="12" month="11" year="99"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note>

This don't look much like XML. Got the point?


An Exception to my Attribute rule

Rules always have exceptions. My rule about not using attributes has one too:

Sometimes I assign ID references to elements in my XML documents. These ID references can be used to access
XML element in much the same way as the NAME or ID attributes in HTML. This example demonstrates this:

<?xml version="1.0"?>
<messages>
<note ID="501">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

<note ID="502">
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not!</body>
</note>
</messages>

The ID in these examples is just a counter, or a unique identifier, to identify the different notes in the XML file.

"Well Formed" XML documents


A "Well Formed" XML document is a document that conforms to the XML syntax rules that we described in the
previous chapter.
The following is a "Well Formed" XML document:

<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

"Valid" XML documents


A "Valid" XML document is a "Well Formed" XML document which conforms to the rules of a Document Type
Definition (DTD).
The following is the same document as above but with an added reference to a DTD:

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "InternalNote.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

</note>

Displaying XML
Displaying XML with JavaScript

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

<html>
<head>
<script language="JavaScript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
nodes = xmlDoc.documentElement.childNodes
to.innerText = nodes.item(0).text
from.innerText = nodes.item(1).text
header.innerText = nodes.item(2).text
body.innerText = nodes.item(3).text
</script>
<title>HTML using XML data</title>
</head>
<body bgcolor="yellow">
<h1>Refsnes Data Internal Note</h1>
<b>To: </b><span id="to"></span>
<br>
<b>From: </b><span id="from"></span>
<hr>
<b><span id="header"></span></b>
<hr>
<span id="body"></span>
</body>
</html>

Displaying XML with CSS

CATALOG
{
background-color: #ffffff;
width: 100%;
}
CD
{
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
TITLE
{
color: #FF0000;
font-size: 20pt;
}
ARTIST
{

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

color: #0000FF;
font-size: 20pt;
}
COUNTRY,PRICE,YEAR,COMPANY
{
Display: block;
color: #000000;
margin-left: 20pt;
}

Displaying XML with XSL


XSL - The Style Sheet of XML?
HTML pages uses predefined tags, and the meaning of these tags is well understood: <p> means a paragraph and
<h1> means a header, and the browser knows how to display these pages.
With XML we can use any tags we want, and the meaning of these tags are not automatically understood by the
browser: <table> could mean a HTML table or maybe a piece of furniture. Because of the nature of XML, there is
no standard way to display an XML document.

In order to display XML documents, it is necessary to have a mechanism to describe how the document should be
displayed. One of these mechanisms is Cascading Style Sheets (CSS), but XSL (eXtensible Stylesheet Language) is
the preferred style sheet language of XML, and XSL is far more sophisticated than the CSS used by HTML.

XSL - More than a Style Sheet


XSL consists of two parts:
a method for transforming XML documents
a method for formatting XML documents

If you don't understand the meaning of this, think of XSL as a language that can transform XML into HTML, a
language that can filter and sort XML data and a language that can format XML data, based on the data value, like
displaying negative numbers in red.

XSL - What can it do?


XSL can be used to define how an XML file should be displayed by transforming the XML file into a format that is
recognizable to a browser. One such format is HTML. Normally XSL does this by transforming each XML element
into an HTML element.

XSL can also add completely new elements into the output file, or remove elements. It can rearrange and sort the
elements, test and make decisions about which elements to display, and a lot more.

<?xml version="1.0" encoding="ISO8859-1" ?>


<?xml-stylesheet type="text/xsl" href="cd_catalog.xsl"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
.
.
.

The XML file and the XSL file


Take a new look at the XML document that you saw in the previous chapter (or open it with IE5):
<?xml version="1.0" encoding="ISO8859-1" ?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
.
.
.

And at the companying XSL stylesheet (or open it with IE5):

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="CATALOG/CD">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Difference between DOM and SAX Parsers

Both DOM and SAX parser are extensively used to read and parse XML file in java and have their own set of
advantage and disadvantage which we will cover in this article. Though there is another way of reading XML file
using XPath in Java which is the more selective approach like SQL statements people tend to stick with XML
parsers. DOM Parser vs SAX parsers is also often viewed in terms of speed, memory consumption and their ability
to process large XML files.

Difference between DOM and SAX XML


DOM XML Parser in Java
DOM Stands for Document Object Model and it represent an XML Document into tree format which each element
representing tree branches. DOM Parser creates an In Memory tree representation of XML file and then parses it, so
it requires more memory and it's advisable to have increased the heap size for DOM parser in order to avoid
Java.lang.OutOfMemoryError:java heap space .

Parsing XML file using DOM parser is quite fast if XML file is small but if you try to read a large XML file using
DOM parser there is more chances that it will take a long time or even may not be able to load it completely simply
because it requires lot of memory to create XML Dom Tree. Java provides support DOM Parsing and you can parse
XML files in Java using DOM parser. DOM classes are in w3c.dom package while DOM Parser for Java is in JAXP
(Java API for XML Parsing) package.

SAX XML Parser in Java


difference between DOM and XML parsers in Java
SAX Stands for Simple API for XML Parsing. This is an event based XML Parsing and it parse XML file step by
step so much suitable for large XML Files. SAX XML Parser fires an event when it encountered opening tag,
element or attribute, and the parsing works accordingly. It’s recommended to use SAX XML parser for parsing large
XML files in Java because it doesn't require to load whole XML file in Java and it can read a big XML file in small

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

parts. Java provides support for SAX parser and you can parse any XML file in Java using SAX Parser, I have
covered an example of reading XML file using SAX Parser here. One disadvantage of using SAX Parser in java is
that reading XML file in Java using SAX Parser requires more code in comparison of DOM Parser.

Difference between DOM and SAX XML Parser


Here are few high-level differences between DOM parser and SAX Parser in Java:
1) DOM parser loads whole XML document in memory while SAX only loads a small part of the XML file in
memory.
2) DOM parser is faster than SAX because it access whole XML document in memory.
3) SAX parser in Java is better suitable for large XML file than DOM Parser because it doesn't require much
memory.
4) DOM parser works on Document Object Model while SAX is an event based XML parser.

That’s all on the difference between SAX and DOM parsers in Java, now it’s up to you on which XML parser you
going to choose. I recommend using DOM parser over SAX parser if XML file is small enough and go with SAX
parser if you don’t know the size of XML files to be processed or they are large.

Content Management System


A content management system (CMS) is a software application or set of related programs that are used to create and
manage digital content. CMSes are typically used for enterprise content management (ECM) and web content
management (WCM). An ECM facilitates collaboration in the workplace by integrating document management,
digital asset management and records retention functionalities, and providing end users with role-based access to the
organization's digital assets. A WCM facilitates collaborative authoring for websites. ECM software often includes a
WCM publishing functionality, but ECM webpages typically remain behind the organization's firewall.

Joomla! is a free and open source content management system (CMS) designed to assist users in building websites
and other online applications. The Joomla open source CMS, which is offered under the General Public License
(GPL) version 2.0

The Joomla Web CMS is considered to be a popular choice for many types of websites, including corporate sites,
news or blogs, government applications, small business sites and sites where secure logins are required. The
ecosystem of Joomla developers and users provide products and services to the Joomla community which has more
than one-half million members and more than 20,000 developers.

Joomla - Installation
System Requirements for Joomla 3.x
Database − MySQL 5.1 +
Web Server −
WAMP (Windows)
LAMP (Linux)
XAMP (Multi-platform)
MAMP (Macintosh)
Create Store Database
Joomla requires MySQL database. So create a new empty database and user/password (for e.g. User as "root" and
password as "root" or else you can set as per your convenience) for Joomla.

Quick Overview of 3 Popular CMS:

The best websites today are powered by easy to use content management systems (CMS) that allow you to make
changes to a website without needing to touch a single line of code.

If you want to get a new, powerful website online, but can’t wait around or shell out the big bucks ($3k+) required
for a custom site, look no further than these three options.

WordPress, Joomla and Drupal all offer great features, tons of customizaions, ease-of-use, and strong security.

WordPress – Best choice for beginners because of it’s ease-of-use, it works especially well for small to medium
sized websites, blogs and smaller e-commerce stores.
Joomla – Great for e-commerce or social networking websites, but requires a basic understanding of technical skills.

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET


WEB TECHNOLOGIES - by G Sreenivasulu Handout - 2

Drupal – The most difficult, but also the most powerful. It requires a familiar understanding of HTML, CSS and
PHP.

WordPress (Best for Beginners)

WordPress is the world’s most popular content management system.


Despite it’s humble blogging beginnings, WordPress has taken the world by storm (literally), powering over over 60
millions websites today.

Drupal is the third most popular content management system available today, used by sites both large and small.

Joomla is the second most popular CMS. It’s like the compromise between WordPress and Drupal.

It’s powerful enough to run most websites without any problems, and it doesn’t require the same level of technical
experience to run as Drupal either.

III B.Tech (R20) - I Semester CSE - A & B Department of CSE , JBIET

You might also like