// compare the size of the JDom Object and the DOM Object. import java.io.*; import org.jdom.*; import org.jdom.input.*; import org.jdom.output.*; public class Compare { public Compare() { System.out.println("inside compare"); } public static void main(String args[]) { Compare comp = new Compare(); if (args.length > 0) { String fileName = args[0]; System.out.println("Xml file to be parsed : " + fileName); int i = (new Integer(args[1])).intValue(); if (i == 1) { primeDom(); comp.buildDom(fileName); } if (i == 2) { primeJDom(); comp.buildJDom(fileName); } } } public void buildDom(String f) { try { System.out.println("inside build Dom"); long start = System.currentTimeMillis(); // dom parsing code here org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); //parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true); //parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true); //Errors errors = new Errors(); //parser.setErrorHandler(errors); parser.parse(f); org.w3c.dom.Document document = parser.getDocument(); // end parsing code long end = System.currentTimeMillis(); System.out.println("Time taken to build Dom: " + (end - start)); } catch(Exception e) { e.printStackTrace(); } } public void buildJDom(String f) { System.out.println("inside build JDom"); try { long start = System.currentTimeMillis(); SAXBuilder builder = new SAXBuilder(); org.jdom.Document doc = builder.build(new File(f)); long end = System.currentTimeMillis(); System.out.println("Time taken to build JDom: " + (end - start)); } catch(Exception e) { e.printStackTrace(); } } /** * primeDOM */ public static void primeDom() { String sdoc = ""; //just run a xerces parse to "prime" the system try { org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new org.xml.sax.InputSource(new StringReader(sdoc))); } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); } } /** * prime JDOM */ public static void primeJDom() { String sdoc = ""; //just run a xerces parse to "prime" the system try { SAXBuilder builder = new SAXBuilder(); org.jdom.Document doc = builder.build(new StringReader(sdoc)); } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); } } }