com.neoworks.util
Class DOMUtils

java.lang.Object
  |
  +--com.neoworks.util.DOMUtils

public class DOMUtils
extends java.lang.Object

DOM Utility functions

Version:
$Revision: 1.2 $
Author:
$Author: nigel $

Method Summary
static java.lang.String DOM2String(org.w3c.dom.Node node)
          Converts the passed DOM Node into a String object.
static java.lang.String DOM2String(org.w3c.dom.Node node, boolean quiet)
          Converts the passed DOM Node into a String object.
static java.lang.String DOM2String(org.w3c.dom.NodeList nodelist)
          Converts the passed DOM NodeList into a String object.
static java.lang.String DOM2String(org.w3c.dom.Node node, org.apache.xml.serialize.OutputFormat outputFormat)
          Converts the passed DOM Node into a String object.
static org.w3c.dom.DocumentFragment moveNodes2DocumentFragment(org.w3c.dom.Document factory, org.w3c.dom.NodeList nodeList)
          Moves the nodes from a NodeList into a new DocumentFragment
static void ReplaceElement(org.w3c.dom.Element oldElement, org.w3c.dom.Element newElement)
          Replace an element in the DOM with a different specified element
static void ReplaceElement(org.w3c.dom.Element oldElement, org.w3c.dom.NodeList newElements)
          Replace an element in the DOM with a list of elements
static org.w3c.dom.Document string2DOM(java.lang.String xmldoc)
          Converts the passed String object into a DOM Document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

string2DOM

public static org.w3c.dom.Document string2DOM(java.lang.String xmldoc)
                                       throws java.lang.Exception
Converts the passed String object into a DOM Document

Parameters:
xmldoc - The string to convert to a DOM
Returns:
A DOM document
Throws:
java.lang.Exception - If the String could not be parsed into a DOM

DOM2String

public static java.lang.String DOM2String(org.w3c.dom.Node node)
Converts the passed DOM Node into a String object. This function currently supports Element, Node, DocumentFragment, Document and Attribute types. Throws a RuntimeException if the Node type passed is not supported.

Parameters:
node - An XML Node to be converted into a string
Returns:
A String representation of the passed XML DOM

DOM2String

public static java.lang.String DOM2String(org.w3c.dom.NodeList nodelist)
Converts the passed DOM NodeList into a String object. This function currently supports Element, Node, DocumentFragment, Document and Attribute types. Throws a RuntimeException if the Node type passed is not supported.

Parameters:
nodelist - An XML NodeList to be converted into a string
Returns:
A String representation of the passed XML DOM

DOM2String

public static java.lang.String DOM2String(org.w3c.dom.Node node,
                                          boolean quiet)
Converts the passed DOM Node into a String object. This function currently supports Element, Node, DocumentFragment, Document and Attribute types. Throws a RuntimeException if the Node type passed is not supported

Parameters:
node - An XML Node to be converted into a string
quiet - If true suppress all XML headers and disable line wrapping
Returns:
A String representation of the passed XML DOM

DOM2String

public static java.lang.String DOM2String(org.w3c.dom.Node node,
                                          org.apache.xml.serialize.OutputFormat outputFormat)
Converts the passed DOM Node into a String object. This function currently supports Element, Node, DocumentFragment, Document and Attribute types. Throws a RuntimeException if the Node type passed is not supported

Parameters:
node - An XML Node to be converted into a string
outputFormat - The OutputFormat to use to convert the Node to a String.
Returns:
A String representation of the passed XML DOM

ReplaceElement

public static void ReplaceElement(org.w3c.dom.Element oldElement,
                                  org.w3c.dom.Element newElement)
                           throws org.w3c.dom.DOMException
Replace an element in the DOM with a different specified element

Parameters:
oldElement - The element to replace
newElement - the element to put in its place
Throws:
org.w3c.dom.DOMException - on error

ReplaceElement

public static void ReplaceElement(org.w3c.dom.Element oldElement,
                                  org.w3c.dom.NodeList newElements)
                           throws org.w3c.dom.DOMException
Replace an element in the DOM with a list of elements

Parameters:
oldElement - The element to replace
newElements - The element to put in its place
Throws:
org.w3c.dom.DOMException - on error

moveNodes2DocumentFragment

public static org.w3c.dom.DocumentFragment moveNodes2DocumentFragment(org.w3c.dom.Document factory,
                                                                      org.w3c.dom.NodeList nodeList)
                                                               throws java.lang.Exception
Moves the nodes from a NodeList into a new DocumentFragment

Parameters:
factory - the factory to use to create the DocumentFragment
nodeList - The Nodes to add to the DocumentFragment
Returns:
the DocumentFactory containg the Nodes passed
Throws:
java.lang.Exception - on error