Part 3 - XML and Browsers
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:
<subject>Comments on XML</subject>
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.
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).
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.
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:
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.
In part 4 I will show you how to format the XML output in the browser.
1999 - 2001 FreeWebmasterHelp.com