LAB SESSION 4: JDOM =================== 0.- Read the article that you can find at: http://www-128.ibm.com/developerworks/java/library/j-jdom/ There is a local copy in 'lab4_en_example.tgz' (Simplify_XML_programming_with_JDOM.html). The source code (with some minor modifications) is in the 'jdomExamples' directory. 1.- Setting everything: - JDOM $ bash $ wget http://www.jdom.org/dist/binary/archive/jdom-1.0.tar.gz $ tar xzvf jdom-1.0.tar.gz - XALAN & XERCES $ wget http://apache.rediris.es/xml/xalan-j/binaries/xalan-j_2_7_0-bin-2jars.tar.gz $ tar xzvf xalan-j_2_7_0-bin-2jars.tar.gz - CLASSPATH $ CLASSPATH=~/JDOM/xalan-j_2_7_0/xalan.jar:~/JDOM/xalan-j_2_7_0/xercesImpl.jar:~/JDOM/jdom-1.0/build/jdom.jar:. $ export CLASSPATH - COMPILE EXAMPLE $ cd jdomExamples/ $ rm Article.class $ javac Article.java 2.- Modify the example so it saves all the rental requests in an xml file. The program should have the following options: - 'reset': Empties the list of requests. - 'rent': gets from the keyboard the rental information and adds it to the xml file. - 'list': lists all the rental requests in xml - 'xsl': lists all the rental requests in html (using an xsl to do the transformation) HINTS AND TIPS: --- - TO ACCESS TO ALL SUB-ELEMENTS OF AN ELEMENT: getChildren() import java.util.List; import java.util.Iterator; public static void accessChildElement(Document myDocument) { Element carsElement = myDocument.getRootElement(); List cars = carsElement.getChildren(); Iterator itr = cars.iterator(); while (itr.hasNext()) { Element carElement = (Element) itr.next(); Element yearElement = carElement.getChild("year"); [...] } } --- PRETTY FORMAT FOR XML: import org.jdom.output.Format; [...] XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); [...] --- READING FROM KEYBOARD: import java.io.BufferedReader; import java.io.InputStreamReader; [...] BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); try { String m; System.out.print ("Type your name: "); System.out.flush(); m = stdin.readLine(); } catch (java.io.IOException e) { e.printStackTrace(); } [...] --- HERE IS AN EXPLANATION OF WHAT "car vin" is: http://www.vehicleidentificationnumber.com/vehicle_identification_numbers_vin_detail.html ---