Programmer's Cookbook

Recipes for the practical programmer

Thursday, February 09, 2006

 

Load XML file with JDOM

Here is a quick template for using the JDOM to load an XML file.  I like JDOM over other DOM models because it is easy to use, takes less code, and is easy to read once you are done.

import java.io.File;
import java.io.IOException;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class SomeClass
{

public SomeMethod ()
{

Document doc = null;

SAXBuilder sb = new SAXBuilder();

try {
doc = sb.build(new File("/path/to/some/file.xml"));
}
catch (JDOMException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}

}

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?