org.wamblee.xml
Class DomUtils

java.lang.Object
  extended by org.wamblee.xml.DomUtils

public final class DomUtils
extends java.lang.Object

Some basic XML utilities for common reoccuring tasks for DOM documents.

Author:
Erik Brakkee

Method Summary
static org.w3c.dom.Document convert(org.dom4j.Document aDocument)
          Converts a dom4j document into a w3c DOM document.
static org.dom4j.Document convert(org.w3c.dom.Document aDocument)
          Converts a W3C DOM document into a dom4j document.
static org.w3c.dom.Document read(java.io.InputStream aIs)
          Parses an XML document from a stream.
static org.w3c.dom.Document read(java.lang.String aDocument)
          Parses an XML document from a string.
static org.w3c.dom.Document readAndValidate(java.io.InputStream aIs, java.io.InputStream aSchema)
          Reads and validates a document against a schema.
static void removeDuplicateAttributes(org.w3c.dom.Node aNode)
          Removes duplicate attributes from a DOM tree.This is useful for postprocessing the output of JTidy as a workaround for a bug in JTidy.
static java.lang.String serialize(org.w3c.dom.Document aDocument)
          Serializes an XML document.
static void serialize(org.w3c.dom.Document aDocument, java.io.OutputStream aOs)
          Serializes an XML document to a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

read

public static org.w3c.dom.Document read(java.lang.String aDocument)
                                 throws XMLException
Parses an XML document from a string.

Parameters:
aDocument - document.
Returns:
Throws:
XMLException

read

public static org.w3c.dom.Document read(java.io.InputStream aIs)
                                 throws XMLException
Parses an XML document from a stream.

Parameters:
aIs - Input stream.
Returns:
Throws:
XMLException

readAndValidate

public static org.w3c.dom.Document readAndValidate(java.io.InputStream aIs,
                                                   java.io.InputStream aSchema)
                                            throws XMLException
Reads and validates a document against a schema.

Parameters:
aIs - Input stream.
aSchema - Schema.
Returns:
Parsed and validated document.
Throws:
XMLException

serialize

public static void serialize(org.w3c.dom.Document aDocument,
                             java.io.OutputStream aOs)
                      throws java.io.IOException
Serializes an XML document to a stream.

Parameters:
aDocument - Document to serialize.
aOs - Output stream.
Throws:
java.io.IOException

serialize

public static java.lang.String serialize(org.w3c.dom.Document aDocument)
                                  throws java.io.IOException
Serializes an XML document.

Parameters:
aDocument - Document to serialize.
Returns:
Serialized document.
Throws:
java.io.IOException

convert

public static org.w3c.dom.Document convert(org.dom4j.Document aDocument)
                                    throws org.dom4j.DocumentException
Converts a dom4j document into a w3c DOM document.

Parameters:
aDocument - Document to convert.
Returns:
W3C DOM document.
Throws:
org.dom4j.DocumentException

convert

public static org.dom4j.Document convert(org.w3c.dom.Document aDocument)
Converts a W3C DOM document into a dom4j document.

Parameters:
aDocument - Document to convert.
Returns:
Dom4j document.

removeDuplicateAttributes

public static void removeDuplicateAttributes(org.w3c.dom.Node aNode)
Removes duplicate attributes from a DOM tree.This is useful for postprocessing the output of JTidy as a workaround for a bug in JTidy.

Parameters:
aNode - Node to remove duplicate attributes from (recursively). Attributes of the node itself are not dealt with. Only the child nodes are dealt with.


Copyright © 2010. All Rights Reserved.