xml
Class DOMToXML

java.lang.Object
  extended by xml.DOMToXML

public class DOMToXML
extends Object

Converts a DOM-document into an XML-stream. Additionally, but only useful for whitespce-stripped DOMs the addIndent(org.w3c.dom.Node) method can be used to add additional whitespace-nodes as seperators to element nodes. This is particularily useful if you want a easy-to-read output.


Field Summary
static int DEFINDENT
          The default indentation (2).
private static Properties output
          Properties of the output.
private static Transformer serializer
          The transformer instance.
private static TransformerFactory transform
          The transformer factory to transform a dom to a stream.
 
Constructor Summary
DOMToXML()
           
 
Method Summary
static Node addIndent(Node source)
          Adds whitespce nodes as seperators between element nodes.
static Node addIndent(Node source, int indent)
          Adds whitespce nodes as seperators between element nodes.
private static void addWhitespaceNode(Document anchor, Element squeeze, int curindent, int indent)
          Recursively add whitespace nodes to elements found.
static Document fillDefaults(Document raw, String dtd)
           
static void main(String[] arg)
           
static void setOutputProperties(Properties oprop)
          Defines properties for the output overruling the default values.
static void setOutputProperty(String key, String value)
          Defines properties for the output overruling the default values.
static void transform(Node doc, File out)
          Transforms a DOM node into an xml-file.
static void transform(Node doc, OutputStream out)
          Transforms a DOM node into an xml-output stream.
static void transform(Node doc, String out)
          Transforms a DOM node into an xml-URL.
static void transform(Node doc, Writer out)
          Transforms a DOM node into an xml-writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFINDENT

public static final int DEFINDENT
The default indentation (2).

See Also:
Constant Field Values

transform

private static TransformerFactory transform
The transformer factory to transform a dom to a stream.


serializer

private static Transformer serializer
The transformer instance.


output

private static Properties output
Properties of the output. Overrules default values.

Constructor Detail

DOMToXML

public DOMToXML()
Method Detail

fillDefaults

public static Document fillDefaults(Document raw,
                                    String dtd)
                             throws TransformerException
Throws:
TransformerException

setOutputProperties

public static void setOutputProperties(Properties oprop)
Defines properties for the output overruling the default values.


setOutputProperty

public static void setOutputProperty(String key,
                                     String value)
Defines properties for the output overruling the default values.


transform

public static void transform(Node doc,
                             OutputStream out)
                      throws TransformerException
Transforms a DOM node into an xml-output stream.

Throws:
TransformerException

transform

public static void transform(Node doc,
                             File out)
                      throws TransformerException
Transforms a DOM node into an xml-file.

Throws:
TransformerException

transform

public static void transform(Node doc,
                             String out)
                      throws TransformerException
Transforms a DOM node into an xml-URL.

Parameters:
out - Must be a String that conforms to the URI syntax.
Throws:
TransformerException

transform

public static void transform(Node doc,
                             Writer out)
                      throws TransformerException
Transforms a DOM node into an xml-writer.

Throws:
TransformerException

addIndent

public static Node addIndent(Node source)
Adds whitespce nodes as seperators between element nodes. Useful to enhance readability in whitespace-stripped DOMs.


addIndent

public static Node addIndent(Node source,
                             int indent)
Adds whitespce nodes as seperators between element nodes. Useful to enhance readability in whitespace-stripped DOMs. The number of spaces for each new level is specified.


addWhitespaceNode

private static void addWhitespaceNode(Document anchor,
                                      Element squeeze,
                                      int curindent,
                                      int indent)
Recursively add whitespace nodes to elements found.


main

public static void main(String[] arg)
                 throws TransformerException
Throws:
TransformerException