XML Quick Tutorial

Zahid Ghadialy
May 2002



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.


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 uses a Document Type Definition (DTD) or an XML Schema to describe the data

        XML with a DTD or XML Schema is designed to be self-descriptive


Lets start XML with one basic example.



<?xml version="1.0"?>





<body>Dont Forget the Party Tonight</body>



In the above example, the first line is the definition line saying that the above file is an XML file. If this line is omitted then this code will still work, but it is not a good idea to omit it.


The <note> is the root element. In XML it is necessary to have a closing tag without which the XML will not work unlike HTML. Also XML is case sensitive. If the starting tag is <to> and the ending tag is <To>, then this will not work. Also it is very important to have all the XML tags properly nested. There could be only one node element. There can be many children (sub elements).


We can have attributes along with the tags. For example we can modify the node element as follows:

<note date="31/10/2002">


Here is another example of XML.



<?xml version="1.0"?>

<!-- This is just a comment -->

<book date="01/11/2002">

<title>My First XML</title>

<prod id="33-657" media="paper"></prod>

<chapter>Introduction to XML

<para>What is HTML</para>

<para>What is XML</para>



<chapter>XML Syntax

<para>Elements must have a closing tag</para>

<para>Elements must be properly nested</para>





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


Now lets see, what can be done with the XML documents. Lets make a food menu with the XML.


<?xml version="1.0"?>

<?xml-stylesheet type="text/css" href="food_catalog.css"?>

<!-- Comment as usual -->




<name>Banana Pizza with Ice Cream</name>


<description>Some wiered description</description>





<name>Strawberry Belgian Waffles</name>


<description>light Belgian waffles covered with strawberries and whipped cream</description>





<name>Berry-Berry Belgian Waffles</name>


<description>light Belgian waffles covered with an assortment of fresh berries and whipped






<name>French Toast</name>


<description>thick slices made from our homemade sourdough bread</description>





<name>Homestyle Breakfast</name>


<description>two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>









Display: block;

background-color: #ffffff;

width: 100%;





color: #0000FF;

font-size: 20pt;

margin-bottom: 30pt;

margin-left: 0;





color: #FF0000;





Display: block;

font-size: 10pt;





margin-right: 0;

color: #000000;








About Us Careers Contribute Advertise

Copyright 2004-2018 3G4G.CO.UK. All rights reserved.
Contact zahidtg(at)yahoo(dot)com for further information