package org.madore.damlengine; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.*; import org.xml.sax.EntityResolver; import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; public final class DamlEngine { private static Document doc; private DamlEngine() { } // Forbid instantiation public static void processDocument() { // ... } public static void main(String[] args) throws Exception { final Resolver resolver = new Resolver(); final DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl(); dbf.setNamespaceAware(true); dbf.setValidating(false); final DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver((EntityResolver)resolver); if ( args.length == 0 ) { System.err.println("expecting filename as argument"); } for (String fname : args) { doc = db.parse(fname); processDocument(); Node node0 = null; Node node = doc; while ( node != null || node0 != null ) { if ( node != null && node.getNodeType() == Node.ELEMENT_NODE ) { Element elt = (Element)node; System.out.print("<"+elt.getTagName()); if ( elt.hasAttributes() ) { NamedNodeMap attrs = elt.getAttributes(); Node n2; for ( int i=0 ; (n2=attrs.item(i)) != null ; i++ ) { Attr attr = (Attr)n2; System.out.print(" "+attr.getName() +"=\"(value)\""); } } if ( ! elt.hasChildNodes() ) { System.out.print(" />"); node = node.getNextSibling(); } else { System.out.print(">"); node0 = node; node = node0.getFirstChild(); } } else if ( node != null && node.getNodeType() == Node.DOCUMENT_NODE ) { node0 = node; node = node0.getFirstChild(); } else if ( node != null ) { if ( node.getNodeType() == Node.TEXT_NODE ) { System.out.print("(text)"); } else if ( node.getNodeType() == Node.COMMENT_NODE ) { System.out.print(""); } else if ( node.getNodeType() == Node.CDATA_SECTION_NODE ) { System.out.print(""); } else { System.out.print(""); } node = node.getNextSibling(); } else { node = node0; node0 = node.getParentNode(); if ( node.getNodeType() == Node.ELEMENT_NODE ) { Element elt = (Element)node; System.out.print(""); } node = node.getNextSibling(); } } } } }