[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XOM micro tutorial
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 MWTFN. 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 http://java.sun.com. 2. Make a working directory. Download XOM.jar there. Get it at http://cafeconleche.org/XOM/XOM.jar. 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(year); date.appendChild("\n "); date.appendChild(month); date.appendChild("\n "); date.appendChild(day); date.appendChild("\n"); year.appendChild("2002"); month.appendChild("09"); day.appendChild("20"); Document doc = new Document(date); String result = doc.getStringForm(); System.out.println(result); } } 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 it.) 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"> <year>2002</year> <month>09</month> <day>20</day> </date> 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 corrections. Happy Friday, Mike
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|