diff options
Diffstat (limited to 'org/madore')
-rw-r--r-- | org/madore/damlengine/DamlEngine.java | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index 80b1f2d..ecbdefd 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -2,15 +2,10 @@ package org.madore.damlengine; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; +import org.w3c.dom.*; import org.xml.sax.EntityResolver; -import org.apache.xerces.dom.DOMImplementationSourceImpl; import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; -import org.apache.xml.serialize.XHTMLSerializer; -import org.apache.xml.serialize.OutputFormat; -@SuppressWarnings("deprecation") public final class DamlEngine { private static Document doc; @@ -25,11 +20,6 @@ public final class DamlEngine { throws Exception { final Resolver resolver = new Resolver(); - final DOMImplementationSourceImpl source - = new DOMImplementationSourceImpl(); - @SuppressWarnings("unused") - final DOMImplementation impl - = source.getDOMImplementation("XML 3.0 Core 3.0 LS 3.0"); final DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl(); dbf.setNamespaceAware(true); dbf.setValidating(false); @@ -43,10 +33,53 @@ public final class DamlEngine { for (String fname : args) { doc = db.parse(fname); processDocument(); - OutputFormat format = new OutputFormat(doc); - XHTMLSerializer serializer = new XHTMLSerializer(format); - serializer.setOutputByteStream(System.out); - serializer.serialize(doc); + 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("<!--(comment)-->"); + } else if ( node.getNodeType() == Node.CDATA_SECTION_NODE ) { + System.out.print("<![CDATA[(cdata)]]>"); + } else { + System.out.print("<!--(some other kind of node)-->"); + } + node = node.getNextSibling(); + } else { + node = node0; + node0 = node.getParentNode(); + if ( node.getNodeType() == Node.ELEMENT_NODE ) { + Element elt = (Element)node; + System.out.print("</"+elt.getTagName()+">"); + } + node = node.getNextSibling(); + } + } } } |