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 3

XML Tutorial
Part 3 - XML and Browsers

Introduction

Now you should know what XML is for and how to write a basic XML document. In this part I will show you how to create a full XML document and load it in a browser, as well and the different ways it can be displayed.

Making The Document

Creating your XML document is as easy as making an HTML page. All you need is a text editor (for example Notepad). Create a new document and enter the XML document into it, for example, the e-mail message from part 2:

<?xml version="1.0"?>
<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>

Then, all you have to do is to save the document with a .xml extension. Now, try loading this file in your browser.
Click Here To Load The File

This is probably quite a surprising result, whatever browser you are using. I will now cover the results for both Internet Explorer and Netscape/Mozilla.

XML In Internet Explorer

Internet Explorer is probably one of the best browsers for viewing XML pages. It provides a hierarchical display of the XML file, color coding the elements and allowing you to expand and collapse the nested elements.

If you don't have Internet Explorer you can see what it looks like in the image below (without the collapsable elements, though).

Screenshot of XML displayed in Internet Explorer

This is proably quite surpising to see, as it doesn't look like any other web page you will have seen before. You may also be surprised that you can't really do much, but this is exactly what XML is. Some sort of program or code must be written to process the data.

Netscape/Mozilla

The Mozilla and Netscape browsers are not as good as Internet Explorer at supporting XML. Mozilla, for example, presents the XML data as plain text:

Screenshot of XML displayed in Mozilla

This is also a valid display of XML, because, as you will have noticed from the code above, there is really no way to tell the browser how to display the data, so it just shows it as plain text.

Which Is Best?

Probably the best way to develop your XML files is to use Internet Explorer. Apart from the fact that it will provide you with a nicely formatted version of your XML file, it also has another benefit. If there is an error in your XML file, Internet Explorer provides a helpful message telling you exactly where the error is and displaying the incorrect piece of code. The latest version of Mozilla will also do this, although its XML formatting is not as good.

How Can I Guarantee The User Will See The Page?

This is the major problem with XML. With so many browsers around there is no way to guarantee that your data will be displayed the way you want it (which is the reason why there are images of the output in this tutorial). Luckily, there are very few occasions where you will want your users to see the raw XML data, and in most cases a piece of software or a script will process the data first. For now, processing the data first is really the best course of action to take.

Part 4

In part 4 I will show you how to format the XML output in the browser.

© 1999 - 2001 FreeWebmasterHelp.com