/** You may copy this example and use it for any purpose, commercial or otherwise. */ import com.ricebridge.xmlman.XmlManager; import com.ricebridge.xmlman.RecordSpec; import java.util.List; /** This is a very simple example that shows you how to load data * using XML Manager. The data to load is taken from * the file "presidents.xml", in the same folder as this Java source * file. The data is loaded and printed to the console, in * traditional "Hello World!" style. * * To compile and run this program, you will need to include xmlman.jar * (in the lib folder of the XML Manager distribution) in your CLASSPATH. */ public class Load { public static void main( String[] args ) { // To use XML Manager, start by creating a new XmlManager object. XmlManager xmlman = new XmlManager(); // Then you need a RecordSpec object. // This tells XML Manager what data to extract from the XML file RecordSpec rs = new RecordSpec( "/list/president", new String[] {"name","email"} ); // And now load the data from the file presidents.xml List data = xmlman.load( "presidents.xml", rs ); // The data we just loaded is available as a List of String[] arrays. // Now we can print it out by looping through it. for( int pres = 0; pres < data.size(); pres++ ) { String[] record = (String[]) data.get(pres); // we use hard-coded array indexes here as the data format is predefined System.out.println( "NAME:"+record[0]+" EMAIL:"+record[1] ); } } }