/* a dom parser that displays all data of an xml file */ import javax.xml.parsers.*; import org.xml.sax.*; import java.io.*; import org.w3c.dom.*; import java.lang.String; public class DomParser{ public static void main(String argv[]) { if (argv.length != 1) { System.err.println("Usage: java DomParser filename"); System.exit(1); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringElementContentWhitespace(true); factory.setValidating(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( new File(argv[0]) ); // this could also read from a URL or any other stream Element root = document.getDocumentElement(); if (root != null) PrintTree(root,0); } catch (SAXException sxe) { // Error generated during parsing System.err.println(sxe); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built System.err.println(pce); } catch (IOException ioe) { System.err.println(ioe); } } // end of main // PrintTree - prints the dom tree, indenting each level // an additional 4 spaces private static void PrintTree(Element e, int indent) { int i; for (i=0;i