summaryrefslogtreecommitdiffstats
path: root/org
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-11 11:10:27 +0200
committerDavid A. Madore <david+git@madore.org>2010-04-11 11:10:27 +0200
commitc5d9cae77b1cf62735550bfe9a1161b72421f5e2 (patch)
tree294f781c5c0043be2dd8fc0d01f8a0158e4092f4 /org
parent06164d04b12fcb561f1f893c837ebfa9c5825d98 (diff)
downloaddamlengine-c5d9cae77b1cf62735550bfe9a1161b72421f5e2.tar.gz
damlengine-c5d9cae77b1cf62735550bfe9a1161b72421f5e2.tar.bz2
damlengine-c5d9cae77b1cf62735550bfe9a1161b72421f5e2.zip
Implement a toy serializer of my own (just the structure).
This should go into a separate class, of course.
Diffstat (limited to 'org')
-rw-r--r--org/madore/damlengine/DamlEngine.java63
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();
+ }
+ }
}
}