Home arrow XML arrow Page 5 - My First XML Document

Creating An XML Document - XML

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.

TABLE OF CONTENTS:
  1. My First XML Document
  2. Tools For Browsing XML
  3. Tools For Parsing XML
  4. Microsoft XML Parser
  5. Creating An XML Document
  6. Tools For The Trade
By: Gayathri Gokul
Rating: starstarstarstarstar / 26
September 22, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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.xsl?>
<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 
5 ->
<xsl:template match= “/”>
<html>
<head>
<title> A Basic Style 
Sheet </title>
</head>
<body>
<xsl:value-of select = “/” />
</body>
</html>
</xsl: 
template>
</xsl:stylesheet> 
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.

Hello, Welcome to XML World.


 
 
>>> More XML Articles          >>> More By Gayathri Gokul
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: