ru.novosoft.dc.core.util
Class DOMService

java.lang.Object
  |
  +--ru.novosoft.dc.core.util.DOMService

public final class DOMService
extends java.lang.Object

The class contains miscellaneous static service methods for DOM construction.


Method Summary
static void appendString(org.w3c.dom.Element elem, java.lang.String string)
          Create a text node containing the specified string and append it to the specified DOM element.
static org.w3c.dom.Element createChildElement(org.w3c.dom.Element elem, java.lang.String tagName)
          Create a new DOM element with the specified tagName, append it to the specified element, and return created element.
static org.w3c.dom.Document createDocument(org.w3c.dom.DOMImplementation handler, java.lang.String tagName, NamespaceHandler namespaceHandler)
          Create a new document with the specified root tagName containing a prefix.
static org.w3c.dom.Document createDocument(org.w3c.dom.DOMImplementation handler, java.lang.String tagName, java.lang.String namespaceAttribute, java.lang.String namespaceURI)
          Create a new document with the specified root tagName and namespace atribute in it.
static org.w3c.dom.Node findNodeWithTextContent(org.w3c.dom.Node node)
          Test the tree of children of the specified node and return the first node (this node or its direct or indirect child) having a single text node child only.
static void removeNodeIfEmpty(org.w3c.dom.Node node)
          Test a node to have no attributes and child nodes and remove it from the DOM tree if both conditions fulfilled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDocument

public static final org.w3c.dom.Document createDocument(org.w3c.dom.DOMImplementation handler,
                                                        java.lang.String tagName,
                                                        java.lang.String namespaceAttribute,
                                                        java.lang.String namespaceURI)
Create a new document with the specified root tagName and namespace atribute in it. This method was designed to avoid duplication of namespace attribute while serializing to XML with some versions of Xerces. The workaround is the following: we create a document using the createDocument method of DOMImplementation. After that we remove the root namespaced node of the document, then create an ordinary node without namespace, and set the namespace attribute manually.

createDocument

public static final org.w3c.dom.Document createDocument(org.w3c.dom.DOMImplementation handler,
                                                        java.lang.String tagName,
                                                        NamespaceHandler namespaceHandler)
Create a new document with the specified root tagName containing a prefix. The namespace atribute is provided with the namespace handler.
Throws:
java.lang.IllegalArgumentException - if the tagName has no prefix or the namespace with the given prefix does not registered in the namespace handler

createChildElement

public static final org.w3c.dom.Element createChildElement(org.w3c.dom.Element elem,
                                                           java.lang.String tagName)
Create a new DOM element with the specified tagName, append it to the specified element, and return created element.

appendString

public static final void appendString(org.w3c.dom.Element elem,
                                      java.lang.String string)
Create a text node containing the specified string and append it to the specified DOM element.

removeNodeIfEmpty

public static final void removeNodeIfEmpty(org.w3c.dom.Node node)
Test a node to have no attributes and child nodes and remove it from the DOM tree if both conditions fulfilled.

findNodeWithTextContent

public static final org.w3c.dom.Node findNodeWithTextContent(org.w3c.dom.Node node)
Test the tree of children of the specified node and return the first node (this node or its direct or indirect child) having a single text node child only. If no such node found, return null.