Google

Wednesday, May 28, 2008

Introduction to 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. You must define your own tags
XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
XML is a W3C Recommendation
The Main Differences between XML and HTML
XML was designed to carry data.
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, while XML is about describing information.

Characteristics of XML:
1. XML is Free and Extensible

XML tags are not predefined. You must "invent" your own tags.
The tags used to mark up HTML documents and the structure of HTML documents is predefined. The author of HTML documents can only use tags that are defined in the HTML standard (like

, , etc.).

XML allows the author to define his own tags and his own document structure.

The following example is a note to Tove from Jani, stored as XML:


Tove
Jani
Reminder
Don't forget me this weekend!


It is important to understand that XML was designed to store, carry, and exchange data. XML was not designed to display data.

2. XML can Separate Data from HTML
With XML, your data is stored outside your HTML.
When HTML is used to display data, the data is stored inside your HTML. With XML, data can be stored in separate XML files. 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.

3. XML is Used to Exchange Data
With XML, data can be exchanged between incompatible 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
4. XML can be Used to Share Data
With XML, plain text files can be used to share data.
Since XML data is stored in plain text format, XML provides a software- and hardware-independent way of sharing data.

This makes it much easier to create data that different applications can work with. It also makes it easier to expand or upgrade a system to new operating systems, servers, applications, and new browsers
5. XML can be Used to Store Data
With XML, plain text files 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
6. XML Can Make your Data More Useful
With XML, your data is available to more users.
Since XML is independent of hardware, software and application, you can make your data available to other than only standard HTML browsers.
Other clients and applications can access your XML files as data sources, like they are accessing databases. Your data can be made available to all kinds of "reading machines" (agents), and it is easier to make your data available for blind people, or people with other disabilities.
7. XML can be Used to Create New Languages
XML is the mother of WAP and WML.
The Wireless Markup Language (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML.
XML Syntax Rules
1. XML documents use a self-describing and simple syntax.
2. All XML Elements Must Have a Closing Tag
3. XML Tags are Case Sensitive
4. XML Elements Must be Properly Nested
5. XML Documents Must Have a Root Element
6. XML Attribute Values Must be Quoted
XML Validation
1. Well Formed XML Documents

XML with correct syntax is Well Formed XML.
A "Well Formed" XML document has correct XML syntax.
A "Well Formed" XML document is a document that conforms to the XML syntax rules.
2. Valid XML Documents
XML validated against a DTD is Valid XML. A "Valid" XML document also conforms to a DTD. A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD).

XML DTD

A DTD defines the legal elements of an XML document. 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 inside an XML document, or as an external reference.
Internal DTD Declaration
If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax:

Example XML document with an internal DTD:

< !a DOCTYPE note [





]>

Tove
Jani
Reminder
Don't forget me this weekend

The DTD above is interpreted like this:!DOCTYPE note defines that the root element of this document is note.!ELEMENT note defines that the note element contains four elements: "to,from,heading,body".!ELEMENT to defines the to element to be of the type "#PCDATA".!ELEMENT from defines the from element to be of the type "#PCDATA".!ELEMENT heading defines the heading element to be of the type "#PCDATA".!ELEMENT body defines the body element to be of the type "#PCDATA".
External DTD Declaration
If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax:

This is the same XML document as above, but with an external DTD:



Tove
Jani
Reminder
Don't forget me this weekend!

And this is the file "note.dtd" which contains the DTD:






Why Use a DTD?
With a DTD, each of your XML files can carry a description of its own format. With a DTD, independent groups of people can agree to use a standard DTD for interchanging data.
Displaying XML with CSS
With CSS (Cascading Style Sheets) you can add display information to an XML document.

Displaying XML with XSL
XSL is the preferred style sheet language of XML. XSL (the eXtensible Stylesheet Language) is far more sophisticated than CSS.