What is XML? The Difference Between XML and HTML

[Pages:7]XML Introduction

XML is a software- and hardware-independent tool for storing and transporting data.

What is XML?

XML stands for eXtensible Markup Language XML is a markup language much like HTML XML was designed to store and transport data XML was designed to be self-descriptive XML is a W3C Recommendation

The 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.

How can XML be used?

1. XML can keep data separated from your HTML 2. XML can be used to store data inside HTML documents 3. XML can be used as a format to exchange information 4. XML can be used to store data in files or in databases

1. 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.

Complied by RAM GOPAL GUPTA ()

2. 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.

3. 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.

4. 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 Architecture

XML Syntax

An example XML document:

Complied by RAM GOPAL GUPTA ()

Tove Jani Reminder Don't forget me this weekend!

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:

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

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

Tove Jani Reminder Don't forget me this weekend!

The last line defines the end of the root element:

Points to remember:

All XML elements must have a closing tag XML tags are case sensitive All XML elements must be properly nested All XML documents must have a root tag Attribute values must always be quoted

Introduction to DTD

The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference.

Internal DTD

This is an XML document with a Document Type Definition:

Complied by RAM GOPAL GUPTA ()

]>

Tove

Jani

Reminder

Don't forget me this weekend!

The DTD is interpreted like this: !ELEMENT note (in line 2) defines the element "note" as having four elements: "to,from,heading,body". !ELEMENT to (in line 3) defines the "to" element to be of the type "CDATA". !ELEMENT from (in line 4) defines the "from" element to be of the type "CDATA" and so on.....

External DTD

This is the same XML document with an external DTD:

Tove Jani Reminder Don't forget me this weekend!

This is a copy of the file "note.dtd" containing the Document Type Definition:

Why use a DTD?

XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.

Complied by RAM GOPAL GUPTA ()

DTD - XML building blocks

XML documents (and HTML documents) are made up by the following building blocks:

Elements, Tags, Attributes, Entities, PCDATA, and CDATA

This is a brief explanation of each of the building blocks:

Elements

Elements are the main building blocks of both XML and HTML documents.

Examples of HTML elements are "body" and "table". Examples of XML elements could be "note" and "message". Elements can contain text, other elements, or be empty. Examples of empty HTML elements are "hr", "br" and "img".

Tags

Tags are used to markup elements.

A starting tag like mark up the beginning of an element, and an ending tag like mark up the end of an element.

Examples: A body element: body text in between. A message element: some message in between

Attributes

Attributes provide extra information about elements.

Attributes are placed inside the start tag of an element. Attributes come in name/value pairs. The following "img" element has an additional information about a source file:

The name of the element is "img". The name of the attribute is "src". The value of the attribute is "computer.gif". Since the element itself is empty it is closed by a " /".

PCDATA

PCDATA means parsed character data.

Complied by RAM GOPAL GUPTA ()

Think of character data as the text found between the start tag and the end tag of an XML element.

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.

Entities

Entities as variables used to define common text. Entity references are references to entities.

Most of you will known 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.

The following entities are predefined in XML:

Entity References < > & " &apos ;

Character < > & " '

XML Schema

A schema is a set of rules for constraining the structure and articulating the information set of XML documents.

Introduction to XSL - The Style Sheet of XML?

HTML pages uses predefined tags, and the meaning of these tags is well understood: means a paragraph and 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: 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.

Complied by RAM GOPAL GUPTA ()

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 consists of two parts:

a method for transforming XML documents a method for formatting XML documents XSL can be used to define how a n XML file should be displayed by transforming the XML f ile 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 int o 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.

XSLT

EXtensible Stylesheet Language Transformation commonly know n as XSLT is a way to transform the XML document into other formats such as XHTML. This tutorial explains the basics of XSLT. It contains chapters discussing all the basic components of XSLT with suitable examples.

How XSLT works: Advantages Here are the advantages of using XSLT:

Independent of programming. Transformations are written in a separate xsl file which is again an XML document.

Output can be altered by simply modifying the transformations in xsl file. No need to change any code. So Web designers can edit the stylesheet and can se e the change in the output quickly.

Complied by RAM GOPAL GUPTA ()

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download