Free Webmaster Help Logo
Tutorials Articles Tools Images Directory Ask Newsletter
*
 

Tutorials
Cookies
ASP
Advanced HTML
Frames & Tables
.htaccess
Rounded Table Corners
Flash 5
FTP
Beginners
Javascript
PHP/MySQL
Site Promotion
Mobile Internet: WML/WAP
Server Side Includes (SSI)
HTML - The Basics
XHTML
Stylesheets
XML
PHP
*

125x125

Related Links
XML.org
XMLNews.org
Stylesheets Tutorial
More XML Sites
*

 
Sitemap | Contact | Link To Us | Advertise
Report A Problem
Home : Tutorials : XML : Part 2

XML Tutorial
Part 2 - Writing XML

Introduction

As you will have read in part I, the way in which XML is written is very similar to HTML. They both use the same system of enclosing pieces of information or data in tags to apply formatting (in the case of HTML or data rules (in the case of XML) to it.

XML Tags

The tags used in XML, as well as being very similar in construction to HTML, also look like HTML tags. They are formed by a word (or a number of words) enclosed inside <> and </> signs. Just like, for example the <font></font> tag in HTML. The difference, of course, though is that XML tags are not pre-defined like HTML ones are. An example could be the XML tag <message> and the end tag </message> which could be used to enclose an e-mail message stored on a web based e-mail system.

Nesting And Structure

Much like HTML tags, XML tags can be nested. Using the example of the e-mail above, this is a piece of XML code:

<message>
<header>
<from>webmaster@gowansnet.com</from>
<to>webmaster@xml.org</to>
<subject>Comments on XML</subject>
</header>
<body>
I think that XML has great potential. It will work very well and will help many people to make much better use of the internet.
</body>
</message>


As you can see. this piece of code includes nested tags. The first element (tag) in the XML code is the <message> element. This is what is called the root element. It defines the bottom level of the document and is saying 'This is an e-mail message'. All the other tags are nested inside this <message> tag. The next tag which appears is the <header> tag. This is saying that the information contained within it is the e-mail header. This also has nested tags. for example the <subject> tag, which appears as part of the header tag. as the subject is part of the header. Something which is often done in HTML is incorrect nesting. For example: the code: <b><i>Bold and italic</b></i> would work correctly in a web browser. even though the italic tags should both be inside the bold tags. This must not be done in XML. It is very important that all XML tags are correctly nested.

XML Correctness

Another point which should be brought up now, is the strictness of XML when writing code. The whole idea of XML is that it should be independent of the platform it is running on. The same code should run the same way on a PC, a Mac, a mobile phone and even a toaster. As XML does not actually do anything (it is just a language for defining data), it is up to software developers to make software to use this data on a particular platform. This means that it is important that all XML code is structured the same way, so that software can easily be developed. Because of this requirement for correct code, it has been decided (and is now a standard) that if any mistakes (for example incorrectly nested tags) are found in XML code, it will not execute, and will just give an error message. This means that when writing XML, you must be very careful about correct syntax.

Declaring XML

The final part of the XML syntax you should learn just now is how to declare an XML document. The correct way of doing this is to use the tag:

<?xml version="1.0"?>

This tells whatever software receives this data that you are writing XML and that it should match the specification for version 1.0. As this is not actually an XML tag it does not require a closing tag.

Part 3

In part 3 I will explain further about how an XML document is displayed by the browser and how to make an XML file.

© 1999 - 2001 FreeWebmasterHelp.com