/* * Main.java */ package netukar.animalia.xml; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import netukar.animalia.Animal; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; /** * * @author Radovan Netuka */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { String filename = "ursus_arctos.xml"; if (args.length == 1) { filename = args[0]; } try { XMLReader parser = XMLReaderFactory.createXMLReader(); AnimalHandler handler = new AnimalHandler(); parser.setContentHandler(handler); parser.parse(new InputSource(new FileInputStream(new File(filename)))); Animal animal = handler.getResult(); System.out.println("Animal:"); System.out.println(" " + animal.getGenus() + " " + animal.getSpecies()); System.out.println("Conservation state: " + animal.getConservation()); System.out.println("Height: " + animal.getMinimalHeight() + " ~ " + animal.getMaximalHeight() + " m"); System.out.println("Weight: " + animal.getMinimalWeight() + " ~ " + animal.getMaximalWeight() + " kg"); System.out.println("Range:"); for (String location : animal.getRange()) { System.out.println(" " + location); } } catch (SAXException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); } catch (IOException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); } } }