OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   XOM micro tutorial

[ Lists Home | Date Index | Thread Index ]

At John Cowan's recommendation
(http://lists.xml.org/archives/xml-dev/200209/msg00631.html), I've tried XOM
and I like what I see. A lot. It's easy to learn, and it was easy to get it
to do the things I wanted it to do without any fuss. My gut reaction is that
XOM is going to be a genuine evolution of previous APIs. Three cheers to the

If you are interested and want an on-ramp, I've written a very quick micro
tutorial. It assumes that you are comfortable with Java. Here ya go:

1. Have a modern version of Java installed on your system. I used J2SE v1.4
when testing this tutorial. If you don't have modern Java, get it at

2. Make a working directory. Download XOM.jar there. Get it at

3. Paste the following program in a file and save it as Date.java in your
working directory:

import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Attribute;

public class Date {

  public static void main(String[] args) {

    Element date = new Element("date");
    date.add(new Attribute("type", "ISO"));
    Element year = new Element("year");
    Element month = new Element("month");
    Element day = new Element("day");
    date.appendChild("\n ");
    date.appendChild("\n ");
    date.appendChild("\n ");
    Document doc = new Document(date);
    String result = doc.getStringForm();



Pretty easy to figure out what's going, isn't it? Nothing arcane. I created
this program out of the little program from the fledgling XOM tutorial. See
it at http://cafeconleche.org/XOM/tutorial.xhtml. (I had to change the file
extension from .xhtml to .html on a local copy to get IE on Win2k to read

4. Now compile it:

javac -classpath XOM.jar Date.java

This of course assumes XOM.jar is in your working directory.

5. Run it:

java -cp .;XOM.jar Date

6. You'll get the following on standard output:

<?xml version="1.0"?>
<date type="ISO">

7. Now you are hooked. Have a look at the JavaDocs at
http://cafeconleche.org/XOM/doc/ for clues on what to do next, start
hacking, and have fun.

If you have problems with this little tutorial, let me know and I'll post

Happy Friday,



News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS