hackorama
hackorama
XML Jump Start [ written circa 1999 ]

1.Introduction

2.Get the tools from the web.

3.Create the Hello World XML/XSL files.

4.Use the tools to process the files.

5.A sample verbose/file-listing

6.What next ?



1. Introduction

Provides step by step instructions on creating your first XML file and parsing it with an XSL file to create a resulting HTML file. Along with detailed instructions on how to get the required tools and how to set them up.

I have spend many hours surfing pages and pages of XML/XSL information to get a grasp of XML a Jump Start page like this would have saved me lot of time, since most of the sites are too detailed for an XML newbie.

We start off with a small "Hello World" XML document, parse it and view it as an HTML file. Once you get the tools and have your first hands on experience with an XML file parsing it will be easier to go to the real XML sites and understand the underlying technologies like DOM, DTD and the various W3C documentation.

TOP

2. Get the tools from the web.

All the tools listed below are written in Java so you require Java installed on your machine.

Linux users can download JDK from Blackdown IRIX users can download from SGI Windows and Solaris users please downlaod from Sun

Follow the installation procedure at the download sites and verify you have the jvm working and the CLASSPATH is set correctly.

Once you have Java installed on your machine You need to down load the following tools.

NOTE: I HAVEN'T TESTED THIS ON WINDOWS, BUT I GUESS THE INSTRUCTIONS SHOULD WORK !

Step 1 Download the files

1. Docuverse - DOM SDK from Docuverse

>>Downlaod

2 XP - an XML Parser in Java from JClark

>>Download

3. SAXON package - a collection of tools for processing XML documents

from MH Kay

>>Download

All the three files are zip files use WinZip on Windows and unzip on UNIX/LINUX

Make a directory called xmltools with three subdirectories dom, xp, saxon copy the 3 downloaded zip files into each subdirectories and unzip them. You will get jar and class files along with documentation and readme files for each tool. You can extract the jar files using the command "jar -xvf xxxx.jar" , which will create subdirectories of organised class files.

A short Note on the tools.

We will be using a class file called StyleSheet.class which is part of the saxon.jar file and is referenced as com.icl.saxon.StyleSheet. This calss file refers to other class files from the dom and xp directories. That is why we need the CLASSPATH set to all those directories. If you expnd the saxon.jar file you can find the StyleSheet.class file at /xmltools/saxon/com/icl/saxon directory. You can also find the other saxon tools listed in the same directory. For this tutorial we will be using only the com.icl.saxon.StyleSheet tool.

Step 2 Install the downloaded files

Now for us to use these tools which are java class files we have to set the Java CLASSPATH variable. So if you installed the files at /your/path/xmltools/ or C:\your\path\xmltools

On Linux/Unix ( Running csh )


#setenv CLASSPATH   /your/path/xmltools/dom:$CLASSPATH
#setenv CLASSPATH   /your/path/xmltools/xp:$CLASSPATH
#setenv CLASSPATH   /your/path/xmltools/saxon:$CLASSPATH
On Linux/Unix ( running sh bash )


#export CLASSPATH=/your/path/xmltools/dom:$CLASSPATH
#export CLASSPATH=/your/path/xmltools/xp:$CLASSPATH
#export CLASSPATH=/your/path/xmltools/saxon:$CLASSPATH
On Windows:


C:> SET CLASSPATH=C:\your\path\xmltools\dom;
    C:\your\path\xmltools\xp;
    C:\your\path\xmltools\saxon;CLASSPATH
Verify the CLASSPATH.

On Linux/UNIX #echo $CLASSPATH

on Windows C:> CLASSPATH

Add the above CLASSPATH settings to your startup file ( .cshrc/.bashrc for Unix/Linux and autoexec.bat for Windows ) So that you don't have to set the path up each time.

For Eg: I have the following line added to my .cshrc

setenv CLASSPATH /usr/people/kishan/xmltools/dom:$CLASSPATH
setenv CLASSPATH /usr/people/kishan/xmltools/xp:$CLASSPATH
setenv CLASSPATH /usr/people/kishan/xmltools/saxon:$CLASSPATH


TOP

3.Create the Hello World XML/XSL files.

Use your favorite editor ( vi ) and create the following two files:

1. hello.xml

<?xml version="1.0" ?>

<?xml-stylesheet href="hello.xsl" type="text/xsl"?>

<myDoc>

<myText>Hello <myFont> XML </myFont> world!</myText>

</myDoc>

2. hello.xsl

<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">

<xsl:apply-templates/>

</xsl:template>

<xsl:template match="/myDoc">

<xsl:apply-templates/>

</xsl:template>

<xsl:template match="myText">

<DIV style="color:red">

<xsl:apply-templates/>

</DIV>

</xsl:template>

<xsl:template match="myFont">

<I>

<xsl:apply-templates/>

</I>

</xsl:template>

</xsl:stylesheet>

TOP

4.Use the tools to process the files.

Please run the Saxon StyleSheet class using java. It takes the XML and XSL files as input and produces an HTML file by applying the XSL Transformations on the parsed XML file.


#java  com.icl.saxon.StyleSheet hello.xml hello.xsl > hello.html
You should have the following hello.html file generated:



<div style="color:red">Hello <I> XML </I> world!</div>

Which will look like this on the browser

Hello XML world!


TOP

5.A sample verbose/file-listing

Following is a file listing on a UNIX/LINUX machine where the above tools where installed and the verbose from running the tools.


kishan:zipfiles>> pwd
/usr/people/kishan/xmltools/zipfiles
kishan:zipfiles>> ls -l
total 5160
drwxr-xr-x    2 kishan   user          76 Oct 14 20:24 ./
drwxr-xr-x    6 kishan   user          63 Oct 14 19:52 ../
-rw-r--r--    1 kishan   user      776672 Oct 14 19:52 domsdk10pr3b.zip
-rw-r--r--    1 kishan   user     1575178 Oct 14 19:52 saxon.zip
-rw-r--r--    1 kishan   user      283651 Oct 14 19:52 xp04-980813.zip
kishan:zipfiles>>
kishan:zipfiles>> cd ..
kishan:xmltools>> pwd
/usr/people/kishan/xmltools
kishan:xmltools>> ls -l
total 40
drwxr-xr-x    6 kishan   user          63 Oct 14 19:52 ./
drwx------   71 kishan   user       12288 Oct 14 19:51 ../
drwxr-xr-x    7 kishan   user        4096 Oct 14 19:51 dom/
drwxr-xr-x    7 kishan   user        4096 Oct 14 19:52 saxon/
drwxr-xr-x    5 kishan   user          90 Oct 14 19:51 xp/
drwxr-xr-x    2 kishan   user          95 Oct 14 19:52 zipfiles/
kishan:xmltools>>
 kishan:xmltools>> cd dom
kishan:dom>> ls
./                 api/               domcore.jar        index.html         
src/
../                com/               domhtml.jar        license.txt
META-INF/          copyright.txt      domsdk10pr3b.zip   org/
kishan:dom>> cd ../xp
kishan:xp>> ls
./                META-INF/         docs/             xp04-980813.zip
../               com/              xp.jar
kishan:xp>> cd ../saxon
kishan:saxon>> ls
./                         ParserManager.properties   doc/                       
samples/                   source.zip
../                        com/                       org/                       
saxon.jar 	           META-INF/                  compiler.xsl               
output.html                saxon.zip
kishan:saxon>>
kishan:saxon>> cd ..
kishan:xmltools>>echo $SHELL
/bin/tcsh
kishan:xmltools>> setenv CLASSPATH /usr/people/kishan/xmltools/dom:
/usr/people/kishan/xmltools/xp:/usr/people/kishan/xmltools/saxon:
$CLASSPATH
kishan:xmltools>> echo $CLASSPATH
/usr/people/kishan/xmltools/dom:/usr/people/kishan/xmltools/xp:
/usr/people/kishan/xmltools/saxon:.:/usr/people/kishan/java/classes:
/usr/local/swing-1.1.1fcs/
kishan:xmltools>>
kishan:xmltools>> cd
kishan:kishan>> cd xmlsamples
kishan:xmlsamples>> pwd
/usr/people/kishan/xmlsamples
kishan:xmlsamples>> ls  hello.*
./           ../          hello.xml    hello.xsl
kishan:xmlsamples>>
kishan:xmlsamples>> java com.icl.saxon.StyleSheet hello.xml 
hello.xsl > hello.html
Elapsed time: 11130 milliseconds
kishan:xmlsamples>>
kishan:xmlsamples>> cat hello.html

<DIV style="color:red">Hello <I> XML </I> world!</DIV>
kishan:xmlsamples>>
TOP

6. What Next ?

Now you had your first on hands experience on XML you can start surfing the web for detailed information on each of the tools the XML XSL documentation at W3 and the resources available at XML.ORG, XML.COM , XMLHack, Mulberrytech etc.

Also you may look at the following topics I have on XML

XML why use it ?

XML how to use it now

XML the future

XML Resources

TOP

Kishan Thomas kishan@hackorama.com

VIEW THE XML - XSL - DTD FOR THIS PAGE !     IE5 USERS CLICK HERE



Saturday, 01-Dec-2001 17:02:35 PST kishan at hackorama dot com