I have just written a program for importing data from an xml file to a database using dom4j. It endend up as a series of xpath statements wrapped in java, – and it works, but I strongly feel that there is a better way of doing this.
What is the preferred way to import data from xml into a db?
Depending on what kind of XML you have, JAXB (which is a standard part of Java SE since 1.6) might be the most straightforward way to deal with it. Just make a class similar to your XML structure, put in the setters and getters for the fields and a @XmlRootElement annotation to the top of the class. Then something like
magically converts your XML file to a Java object. Then it should be easy to write to the DB of your choice.