Professional Documents
Culture Documents
Module - II
What is XML?
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.
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.
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.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<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>
</note>
<p>This is a paragraph
<p>This is another paragraph
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Opening and closing tags must therefore be written with the same case:
<Message>This is incorrect</message>
<message>This is correct</message>
In XML all elements must be properly nested within each other like this
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>
<subchild>
</subchild>
</child>
</root>
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
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<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>
Why should you avoid using attributes? Should you just take my word for it? These are some of the problems using
attributes:
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:
<?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>
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.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?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>
</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>
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;
}
COUNTRY,PRICE,YEAR,COMPANY
{
Display: block;
color: #000000;
margin-left: 20pt;
}
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.
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 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.
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
.
.
.
<?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>
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.
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.
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.
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.
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.
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.
Drupal – The most difficult, but also the most powerful. It requires a familiar understanding of HTML, CSS and
PHP.
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.