/* a dom parser that displays only element tags */ import javax.xml.parsers.*; import org.xml.sax.*; import java.io.*; import org.w3c.dom.*; import java.lang.String; public class DomParser1{ 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.setValidating(true); // factory.setNamespaceAware(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) Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); x.printStackTrace(); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built pce.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } } // end of main // PrintTree - prints the dom tree, indenting each level // an additional 4 spaces private static void PrintTree(Element e, int indent) { String s = e.getTagName(); int i; for (i=0;i