We have dealt with some basic XML concepts already, so now we are prepared to leap forward and take a closer look at this powerful language. The X in XML stands for eXtensible- in other words, the language can be extended to meet the requirements of a specific situation.
This part explores how to build an XML document. First we will begin with a simple XML document. In Part I, we have already briefly dealt with XML tags, attributes, elements, namespaces and rule-based systems of both DTD and Schemas. Albeit, writing your first XML document is going to be so easy, we are going to dive right in and write one.
Point To Note: This basic XML document contains one element, called Basic. This is really the essence of XML: the ability to define your own meaning and structure to the document. So open your favorite text editor and type the content of Example 1.1.
Example 1.1: A Basic XML Document
<?xml version = 1.0 ?>
<?xml-stylesheet type = text/xsl href=
<Basic> Hello, Welcome To The XML World. </Basic>
Now, save the file as HelloWorld.xml. If you are using Notepad, then in the Save
as Dialog box be sure to select all files form the Save as Type drop-down list. If you dont note pad will save as .txt file, and you may not be able to open the document in an XML Processor. You can also rap the file name in quotes as an alternative.
Next, let us develop a simple Style Sheet so we can use the file in a browser. This step isnt really necessary, because XML Parsers, including the one that comes with IE5 and onwards will parse the document and reveal its structure. But I just want to give you something here that looks familiar, and most people have by now seen a simple web page.
Example 1.2: A Basic XSL(T) Document
<?xml version= “1.0” ?>
<xsl:stylesheet version= “1.0” xmlns:xsl = “http://www.w3.org/1999/XSL/Transform”>
xmlns:xsl = http://www.w3.org/TR/WD-xsl for most versions of Internet Explorer
<xsl:template match= “/”>
<title> A Basic Style
<xsl:value-of select = “/” />
Next, save the file as Basic.xsl in the same directoryu or folder as HelloWorld.xml.
The browser must be able to access it in order to view HelloWorld.xml.
If you have Netscape, you can choose Open File from the File menu and nagivate to the directory in which you saved HelloWorld.xml. Then Open the file in the Netscape, and the screen will have something like this.
The file Basic.xml as rendered by Netscape: File:///c:/filepath/HelloWorld.xml
Hello, Welcome To The XML World.
Note: You dont have to build a Style Sheet in Netscape. Netscape will render the document using built-in style sheet based on Cascading style sheet (CSS).
If you have IE5 or onwards, choose File-Open to navigate to HelloWorld.xml. You may need to swap the portion of the XSL code that reads xmlns:xsl= http//:www.w3.org/1999/xsl/Transform for the commented code that reads xmlns:xsl = http//www.w3.org/TR/WD-xsl and resave Basic.xmlThe page should now display looking like the screen below:
The file HellowWorld.xml as rendered by Internet Explorer. C:\filepathHelloWorld.xml.