com.ibm.commons.xml
Class DOMUtil

java.lang.Object
  extended by com.ibm.commons.xml.DOMUtil

public class DOMUtil
extends java.lang.Object

W3C DOM Utilities.

A set of utility methods that allow clients to perform various DOM manipulations.


Constructor Summary
DOMUtil()
           
 
Method Summary
static void addBigDecimal(org.w3c.dom.Element parent, java.lang.String elementName, java.math.BigDecimal value)
          Add a child element to a parent element.
static void addBigDecimal(org.w3c.dom.Element parent, java.lang.String elementName, java.math.BigDecimal value, java.lang.String namespace)
          Add a child element to a parent element.
static void addBoolean(org.w3c.dom.Element parent, java.lang.String elementName, boolean value)
          Add a child element to a parent element.
static void addBoolean(org.w3c.dom.Element parent, java.lang.String elementName, boolean value, java.lang.String namespace)
          Add a child element to a parent element.
static void addDate(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Date value)
          Add a child element to a parent element.
static void addDate(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Date value, java.lang.String namespace)
          Add a child element to a parent element.
static void addDouble(org.w3c.dom.Element parent, java.lang.String elementName, double value)
          Add a child element to a parent element.
static void addDouble(org.w3c.dom.Element parent, java.lang.String elementName, double value, java.lang.String namespace)
          Add a child element to a parent element.
static void addInteger(org.w3c.dom.Element parent, java.lang.String elementName, int value)
          Add a child element to a parent element.
static void addInteger(org.w3c.dom.Element parent, java.lang.String elementName, int value, java.lang.String namespace)
          Add a child element to a parent element.
static void addLong(org.w3c.dom.Element parent, java.lang.String elementName, long value)
          Add a child element to a parent element.
static void addLong(org.w3c.dom.Element parent, java.lang.String elementName, long value, java.lang.String namespace)
          Add a child element to a parent element.
static void addNode(org.w3c.dom.Element parent, java.lang.String elementName)
          Add a child element to a parent element.
static void addNode(org.w3c.dom.Element parent, java.lang.String elementName, java.lang.String namespaceURI)
          Add a child element to a parent element.
static void addString(org.w3c.dom.Element parent, java.lang.String elementName, java.lang.String value)
          Add a child element to a parent element.
static void addString(org.w3c.dom.Element parent, java.lang.String elementName, java.lang.String value, java.lang.String namespaceURI)
          Add a child element to a parent element.
static void addTime(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Time value)
          Add a child element to a parent element.
static void addTime(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Time value, java.lang.String namespaceURI)
          Add a child element to a parent element.
static void addTimestamp(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Timestamp value)
          Add a child element to a parent element.
static void addTimestamp(org.w3c.dom.Element parent, java.lang.String elementName, java.sql.Timestamp value, java.lang.String namespaceURI)
          Add a child element to a parent element.
static void clearDocument(org.w3c.dom.Document doc)
          Clear all of the content from the specified document
static org.w3c.dom.Document clone(org.w3c.dom.Document inDoc)
          Clone a Document.
static int compareLocations(org.w3c.dom.Node node1, int offset1, org.w3c.dom.Node node2, int offset2)
          compare two nodes.
static com.ibm.commons.xml.xpath.NodeListImpl concatNodeLists(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)
          This method will return a nodelist containing all the nodes from 2 given nodeLists.
static org.w3c.dom.Document createDocument()
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(org.w3c.dom.DocumentType docType)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.InputStream is)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.InputStream is, boolean ignoreBlanks)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.InputStream is, boolean ignoreBlanks, boolean resolveEntities)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.InputStream is, boolean ignoreBlanks, boolean resolveEntities, boolean validate)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.Reader is)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.Reader is, boolean ignoreBlanks)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.Reader is, boolean ignoreBlanks, boolean resolveEntities)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.io.Reader is, boolean ignoreBlanks, boolean resolveEntities, boolean validate)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.lang.String xmlText)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.lang.String xmlText, boolean ignoreBlanks)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.lang.String namespaceURI, java.lang.String qualifiedName)
          Create a new W3C Document.
static org.w3c.dom.Document createDocument(java.lang.String namespaceURI, java.lang.String qualifiedName, org.w3c.dom.DocumentType doctype)
          Create a new W3C Document.
static org.w3c.dom.DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicId, java.lang.String systemId)
          Create a new W3C DocumentType.
static org.w3c.dom.Element createElement(org.w3c.dom.Document document, org.w3c.dom.Element parent, java.lang.String name)
          Create an element with the specified name and add it as a child of the specified parent.
static org.w3c.dom.Element createElement(org.w3c.dom.Document document, java.lang.String name)
          Create an element with the specified name and add it as a child of the specified parent.
static java.lang.Object createNodes(org.w3c.dom.Node node, java.lang.String xpathExpr)
          Create a node based on an XPath expression object.
static java.lang.Object createNodes(org.w3c.dom.Node node, java.lang.String xpathExpr, boolean useCache)
          Create a node based on an XPath expression object.
static com.ibm.commons.xml.xpath.XPathExpression createXPath(java.lang.String xpathExpr)
          Create an XPath expression object.
static com.ibm.commons.xml.xpath.XPathExpression createXPath(java.lang.String xpathExpr, boolean useCache)
          Create an XPath expression object.
static org.w3c.dom.Document emptyDocument(org.w3c.dom.Document doc)
          Remove the content of an existing document.
static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node, java.lang.String xpathExpr)
          Evaluate an XPath expression.
static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node, java.lang.String xpathExpr, boolean useCache)
          Evaluate an XPath expression.
static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node, java.lang.String xpathExpr, com.ibm.commons.xml.NamespaceContext nsContext)
          Evaluate an XPath expression.
static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node, java.lang.String xpathExpr, com.ibm.commons.xml.NamespaceContext nsContext, boolean useCache)
          Evaluate an XPath expression.
static boolean findChildAtAnyLevel(org.w3c.dom.Node parent, org.w3c.dom.Node child)
          Search through all child nodes and sub child nodes of the given parent node, and return true, if the given child node is ever found.
static org.w3c.dom.NodeList getAllChildElementsByName(org.w3c.dom.Element parent, java.lang.String name)
          Find all element of a given name that is a child or subchild to n levels of a given parent element.
static org.w3c.dom.Attr getAttributeIgnoreCase(org.w3c.dom.Element element, java.lang.String attributeName)
          Gets the DOM attribute of element with the given name.
static java.lang.String getAttributeValue(org.w3c.dom.Element e, java.lang.String key)
          This returns the attribute value for the attribute of the input element with the given name and within no namespace.
static java.lang.String getAttributeValueIgnoreCase(org.w3c.dom.Element element, java.lang.String attributeName)
          Gets the value of DOM attribute of element with the given name It returns the first attribute value that matches the name, regardless the case.
static org.w3c.dom.NodeList getChildElementsByTagName(org.w3c.dom.Element element, java.lang.String tag)
          Behaves like getElementsByTagName() but only return nodes that are the children of a specified element.
static org.w3c.dom.NodeList getChildElementsByTagNameNS(org.w3c.dom.Element element, java.lang.String uri, java.lang.String tag)
          Behaves like getElementsByTagNameNS() but only return nodes that are the children of a specified element.
static org.w3c.dom.NodeList getChildNodesToNLevels(org.w3c.dom.Node parent)
          Find all children and subChildren of the given parent to n sub levels.
static java.util.Iterator getChildren(org.w3c.dom.Node node)
          Get the list of the children Element.
static java.util.List<org.w3c.dom.Node> getChildrenAsList(org.w3c.dom.Element elt)
          Create a java.util.List contain the child nodes of the specified element.
static java.lang.String getChildText(org.w3c.dom.Element element, java.lang.String nodeName)
          Returns the textual content of the named child element, or null if there's no such child.
static java.lang.Object getContextNodes(org.w3c.dom.Document doc)
          Get the current XPath context result that is associated to a document.
static org.w3c.dom.NodeList getElementsByName(org.w3c.dom.Element parent, java.lang.String name)
          Find a element by name.
static org.w3c.dom.NodeList getElementsByNameNS(org.w3c.dom.Element parent, java.lang.String namespaceURI, java.lang.String name)
          Find a element by name.
static org.w3c.dom.Element getFirstElementAtAnyDepthByNodeName(org.w3c.dom.Element parent, java.lang.String name)
          Find the first element that is a child or subchild under a given Element parent.
static org.w3c.dom.Element getFirstElementByName(org.w3c.dom.Element parent, java.lang.String name)
          Find a element by name.
static org.w3c.dom.Element getFirstElementByNameNS(org.w3c.dom.Element parent, java.lang.String namespaceURI, java.lang.String name)
          Find a element by name.
static java.lang.String getNamespaceContextAsString(com.ibm.commons.xml.NamespaceContext namespaceContext)
          Debugging function for NamespaceContext.
static java.lang.String getNamespacePrefix(org.w3c.dom.Node parentNode, java.lang.String preferredPrefix, java.lang.String nsUri)
          Traverse a node, and parent nodes, for a namespace URI.
static org.w3c.dom.Node getNode(org.w3c.dom.Node node, int offset)
          Convert the parent, offset into the child node.
static int getOffsetInParent(org.w3c.dom.Node node)
          Helper method to get the offset of a given node with respect to its parent.
static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
          Return the owner document for the specified node.
static XMLParserDriver getParserDriver()
          Get the internal XML parser driver used.
static com.ibm.commons.xml.NamespaceContext getSelectionNamespaces(org.w3c.dom.Document doc)
          Get the selection NamespaceContext use during the XPath evaluation on the document.
static java.lang.String getSourceReferenceId(org.w3c.dom.Node node)
          Return the source reference id for the specified node.
static java.lang.String getText(org.w3c.dom.Node n)
          Returns the textual content directly held under this element as a string.
static java.lang.String getTextValue(org.w3c.dom.Node node)
          Get the text associated with a node.
static java.lang.String getXMLString(org.w3c.dom.Node node)
          Method to convert a DOM document into a string with no XML declaration line.
static java.lang.String getXMLString(org.w3c.dom.Node node, boolean compact)
          Method to convert a DOM document into a string with no XML declaration line.
static java.lang.String getXMLString(org.w3c.dom.Node node, boolean compact, boolean xmldecl)
          Method to convert a DOM document into a string.
static java.lang.String getXMLString(org.w3c.dom.Node node, com.ibm.commons.xml.Format format)
          Method to convert a DOM document into a string.
static com.ibm.commons.xml.XPathContext getXPathContext(org.w3c.dom.Document doc)
          Get the current XPath contextthat is associated to a document.
static com.ibm.commons.xml.xpath.XPathExpressionFactory getXPathExpressionFactory()
          Get the internal XPath factory used.
static boolean hasChildren(org.w3c.dom.Element element)
          Deprecated. use element.hasChildNode() instead
static boolean hasRootElement(org.w3c.dom.Document document)
          Returns whether a DOM has a root.
static org.w3c.dom.Node insertAfter(org.w3c.dom.Node parent, org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          Inserts the node newChild after the existing child node refChild.
static boolean isNamespaceAttribute(org.w3c.dom.Attr attribute)
          Determines if an Attribute is a namespace attribute.
static boolean moveNodeDown(org.w3c.dom.Node node)
          Move an element prior to his previous sibling.
static boolean moveNodeUp(org.w3c.dom.Node node)
          Move an element prior to his previous sibling.
static java.lang.Object node(org.w3c.dom.Node node, java.lang.String xpath)
          Evaluate the given XPath expression on the given document, and returns the first element or attribute that match this XPath.
static java.lang.Object node(org.w3c.dom.Node node, java.lang.String xpath, com.ibm.commons.xml.NamespaceContext selectionNS)
          Evaluate the given XPath expression on the given document, and returns the first element or attribute that match this XPath.
static java.lang.Object[] nodes(org.w3c.dom.Node node, java.lang.String xpath)
          Evaluate the given XPath expression on the given document, and returns an array with all elements and attributes that match this XPath.
static java.lang.Object[] nodes(org.w3c.dom.Node node, java.lang.String xpath, com.ibm.commons.xml.NamespaceContext selectionNS)
          Evaluate the given XPath expression on the given document, and returns an array with all elements and attributes that match this XPath.
static void popXPathContext(org.w3c.dom.Document doc)
          Remove the latest XPath context that has been set to the document An XML document contains a base XPath that is used when evaluating XPath against a node.
static void pushXPathContext(org.w3c.dom.Document doc, java.lang.String xPathContext)
          Push an XPath context to an existing document.
static void removeAttributeIgnoreCase(org.w3c.dom.Element element, java.lang.String attributeName)
          Removes the DOM attribute from element with the given name.
static void removeChildren(org.w3c.dom.Node node)
          Remove all the children from a node.
static org.w3c.dom.Element rootElement(org.w3c.dom.Document document)
          Deprecated. use document.getDocumentElement() instead
static void serialize(java.io.File file, org.w3c.dom.Node node, com.ibm.commons.xml.Format format)
          Serialize a node to a file.
static void serialize(java.io.OutputStream os, org.w3c.dom.Node node, boolean compact, boolean xmldecl)
          Serialize a node to a stream.
static void serialize(java.io.OutputStream os, org.w3c.dom.Node node, com.ibm.commons.xml.Format format)
          Serialize a node to a stream.
static void serialize(java.io.Writer w, org.w3c.dom.Node node, boolean compact, boolean xmldecl)
          Serialize a node to a writer.
static void serialize(java.io.Writer w, org.w3c.dom.Node node, com.ibm.commons.xml.Format format)
          Serialize a node to a writer.
static void setDocument(org.w3c.dom.Document source, org.w3c.dom.Document target)
          Set the content of the target document from the sourec document.
static void setFilterIndex(org.w3c.dom.Document doc, int index)
          Set the filter index on the current XPath context that is associated with the specified document.
static void setSelectionNamespaces(org.w3c.dom.Document doc, com.ibm.commons.xml.NamespaceContext selectionNS)
          Set the namespaces map use during the XPath evaluation on the document.
static void setTextValue(org.w3c.dom.Node node, java.lang.String value)
          Set the text associated with a node.
static void setTextValue(org.w3c.dom.Node node, java.lang.String value, boolean cdata)
           
static void setValue(org.w3c.dom.Node node, java.lang.String path, java.lang.String value)
          Set the value of the first XPath matching element.
static void setValue(org.w3c.dom.Node node, java.lang.String path, java.lang.String value, com.ibm.commons.xml.NamespaceContext selectionNS)
          Set the value of the first XPath matching element.
static void setXMLString(org.w3c.dom.Document target, java.lang.String s)
          Reads the given string to update the document content.
static java.lang.String value(org.w3c.dom.Node node, java.lang.String xpath)
          Get a string value from the first XPath matching element.
static java.lang.String value(org.w3c.dom.Node node, java.lang.String xpath, com.ibm.commons.xml.NamespaceContext selectionNS)
          Get a string value from the first XPath matching element.
static java.lang.String[] values(org.w3c.dom.Node node, java.lang.String xpath)
          Get the string values from the XPath matching elements.
static java.lang.String[] values(org.w3c.dom.Node node, java.lang.String xpath, com.ibm.commons.xml.NamespaceContext selectionNS)
          Get the string values from the XPath matching elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtil

public DOMUtil()
Method Detail

getParserDriver

public static XMLParserDriver getParserDriver()
Get the internal XML parser driver used. This object is not meant to be used directly. Use DOMUtil high level methods instead.

Returns:
the XML parser driver

getXPathExpressionFactory

public static com.ibm.commons.xml.xpath.XPathExpressionFactory getXPathExpressionFactory()
Get the internal XPath factory used. This object is not meant to be used directly. Use DOMUtil high level methods instead.

Returns:
the XPath factory

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String namespaceURI,
                                                  java.lang.String qualifiedName,
                                                  org.w3c.dom.DocumentType doctype)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String namespaceURI,
                                                  java.lang.String qualifiedName)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(org.w3c.dom.DocumentType docType)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument()
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream is,
                                                  boolean ignoreBlanks)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream is,
                                                  boolean ignoreBlanks,
                                                  boolean resolveEntities)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream is,
                                                  boolean ignoreBlanks,
                                                  boolean resolveEntities,
                                                  boolean validate)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream is)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.Reader is,
                                                  boolean ignoreBlanks)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.Reader is,
                                                  boolean ignoreBlanks,
                                                  boolean resolveEntities)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.Reader is,
                                                  boolean ignoreBlanks,
                                                  boolean resolveEntities,
                                                  boolean validate)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.io.Reader is)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xmlText,
                                                  boolean ignoreBlanks)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xmlText)
                                           throws XMLException
Create a new W3C Document.

Returns:
the newly created document
Throws:
XMLException

createDocumentType

public static org.w3c.dom.DocumentType createDocumentType(java.lang.String qualifiedName,
                                                          java.lang.String publicId,
                                                          java.lang.String systemId)
                                                   throws XMLException
Create a new W3C DocumentType.

Returns:
the newly created document
Throws:
XMLException

rootElement

public static org.w3c.dom.Element rootElement(org.w3c.dom.Document document)
Deprecated. use document.getDocumentElement() instead

Returns the root element of a DOM. This is for compatibility only.

Parameters:
document - the source document
Returns:
the DOM root element

hasRootElement

public static boolean hasRootElement(org.w3c.dom.Document document)
Returns whether a DOM has a root.

Parameters:
document - the source document
Returns:
true if a root element exists, false otherwise

hasChildren

public static boolean hasChildren(org.w3c.dom.Element element)
Deprecated. use element.hasChildNode() instead

Check if an element has some children. This is for compatibility only.

Parameters:
element - the element to check
Returns:
true if the element has at least one child

removeChildren

public static void removeChildren(org.w3c.dom.Node node)
Remove all the children from a node. This method is surprisingly absent from the Node interface.

Parameters:
node - the node to remove the children

emptyDocument

public static org.w3c.dom.Document emptyDocument(org.w3c.dom.Document doc)
Remove the content of an existing document.

Parameters:
doc - the document to clear
Returns:
the empty

getTextValue

public static java.lang.String getTextValue(org.w3c.dom.Node node)
Get the text associated with a node. If case of an Element, then it concatenate all the Text parts into one big.

Returns:
the text associated to the node

setTextValue

public static void setTextValue(org.w3c.dom.Node node,
                                java.lang.String value)
Set the text associated with a node. If case of an Element, it finds the first occurence of text and change its content. If none is available, then it add a new one at the end of the content. For the other nodes, it then calls setNodeValue()


setTextValue

public static void setTextValue(org.w3c.dom.Node node,
                                java.lang.String value,
                                boolean cdata)

getChildren

public static java.util.Iterator getChildren(org.w3c.dom.Node node)
Get the list of the children Element. Only the elements are extracted here.

Returns:
an iterator on the children elements

serialize

public static void serialize(java.io.File file,
                             org.w3c.dom.Node node,
                             com.ibm.commons.xml.Format format)
                      throws XMLException
Serialize a node to a file.

Parameters:
file - the java.io.File
node - the source node
format - the desired output format
Throws:
XMLException

serialize

public static void serialize(java.io.OutputStream os,
                             org.w3c.dom.Node node,
                             com.ibm.commons.xml.Format format)
                      throws XMLException
Serialize a node to a stream.

Parameters:
os - the output stream
node - the source node
format - the desired output format
Throws:
XMLException

serialize

public static void serialize(java.io.OutputStream os,
                             org.w3c.dom.Node node,
                             boolean compact,
                             boolean xmldecl)
                      throws XMLException
Serialize a node to a stream. The serialization is done using UTF-8 encoding.

Parameters:
os - the output stream
node - the source node
compact - if true, the document does'nt contains any formatting text (blanks, new lines..)
xmldecl - if true, include the XML declaration statement
Throws:
XMLException

serialize

public static void serialize(java.io.Writer w,
                             org.w3c.dom.Node node,
                             com.ibm.commons.xml.Format format)
                      throws XMLException
Serialize a node to a writer.

Parameters:
w - the writer
node - the source node
format - the desired output format
Throws:
XMLException

serialize

public static void serialize(java.io.Writer w,
                             org.w3c.dom.Node node,
                             boolean compact,
                             boolean xmldecl)
                      throws XMLException
Serialize a node to a writer. The serialization is done using UTF-8 encoding.

Parameters:
w - the writer
node - the source node
compact - if true, the document does'nt contains any formatting text (blanks, new lines..)
xmldecl - if true, include the XML declaration statement
Throws:
XMLException

getXMLString

public static java.lang.String getXMLString(org.w3c.dom.Node node,
                                            com.ibm.commons.xml.Format format)
                                     throws XMLException
Method to convert a DOM document into a string.

If xmlDecl is false, the resulting string won't contain an XML declaration. (<?xml version="1.0"?>)

If compact is true, the resulting string will be compacted (no indent, no empty lines).

Parameters:
node - the source XML node
compact - if true, the document does'nt contains any formatting text (blanks, new lines..)
xmldecl - if true, include the XML declaration statement
Returns:
the document as a string
Throws:
XMLException - if an error occurred

getXMLString

public static java.lang.String getXMLString(org.w3c.dom.Node node,
                                            boolean compact,
                                            boolean xmldecl)
                                     throws XMLException
Method to convert a DOM document into a string.

If xmlDecl is false, the resulting string won't contain an XML declaration. (<?xml version="1.0"?>)

If compact is true, the resulting string will be compacted (no indent, no empty lines).

Parameters:
node - the source XML node
compact - if true, the document does'nt contains any formatting text (blanks, new lines..)
xmldecl - if true, include the XML declaration statement
Returns:
the document as a string
Throws:
XMLException - if an error occurred

getXMLString

public static java.lang.String getXMLString(org.w3c.dom.Node node,
                                            boolean compact)
                                     throws XMLException
Method to convert a DOM document into a string with no XML declaration line.

If compact is true, the resulting string will be compacted (no indent, no empty lines).

Parameters:
node - the source XML node
compact - if true, the document does'nt contains any formatting text (blanks, new lines..)
Returns:
the document as a string
Throws:
XMLException - if an error occurred

getXMLString

public static java.lang.String getXMLString(org.w3c.dom.Node node)
                                     throws XMLException
Method to convert a DOM document into a string with no XML declaration line. The resulting string is not compacted (indent, blank lines)

Parameters:
node - the source XML node
Returns:
the document as a string
Throws:
XMLException - if an error occurred

setXMLString

public static void setXMLString(org.w3c.dom.Document target,
                                java.lang.String s)
                         throws XMLException
Reads the given string to update the document content. The string is parsed to an XML DOM, which is then assigned to the document

Parameters:
doc - the XML node to update
s - the XML string to parse
Throws:
XMLException - if an error occurred

clearDocument

public static void clearDocument(org.w3c.dom.Document doc)
Clear all of the content from the specified document

Parameters:
doc -

setDocument

public static void setDocument(org.w3c.dom.Document source,
                               org.w3c.dom.Document target)
Set the content of the target document from the sourec document.

Parameters:
source -
target -

pushXPathContext

public static void pushXPathContext(org.w3c.dom.Document doc,
                                    java.lang.String xPathContext)
                             throws XMLException
Push an XPath context to an existing document. An XML document contains a base XPath that is used when evaluating XPath against a node. This base XPath is composed by the aggregating all the XPath contexts pushed to the document.

Parameters:
doc - the source document
xPathContext - the XPath context to push to the document
Throws:
XMLException

popXPathContext

public static void popXPathContext(org.w3c.dom.Document doc)
                            throws XMLException
Remove the latest XPath context that has been set to the document An XML document contains a base XPath that is used when evaluating XPath against a node. This base XPath is composed by the aggregating all the XPath contexts pushed to the document.

Parameters:
doc - the source document
Throws:
XMLException

getContextNodes

public static java.lang.Object getContextNodes(org.w3c.dom.Document doc)
Get the current XPath context result that is associated to a document. The result is either a Node or a NodeList.

Parameters:
doc - the source document

getXPathContext

public static com.ibm.commons.xml.XPathContext getXPathContext(org.w3c.dom.Document doc)
Get the current XPath contextthat is associated to a document.

Parameters:
doc - the source document

setFilterIndex

public static void setFilterIndex(org.w3c.dom.Document doc,
                                  int index)
                           throws XMLException
Set the filter index on the current XPath context that is associated with the specified document.

Parameters:
doc -
index -
Throws:
XMLException

setSelectionNamespaces

public static void setSelectionNamespaces(org.w3c.dom.Document doc,
                                          com.ibm.commons.xml.NamespaceContext selectionNS)
Set the namespaces map use during the XPath evaluation on the document.

Parameters:
doc - the source document
selectionNS - the NamespaceContext used during XPath evaluation on the document, in order to resolve namespaces.

getSelectionNamespaces

public static com.ibm.commons.xml.NamespaceContext getSelectionNamespaces(org.w3c.dom.Document doc)
Get the selection NamespaceContext use during the XPath evaluation on the document.

Parameters:
doc - the source document

getNamespaceContextAsString

public static java.lang.String getNamespaceContextAsString(com.ibm.commons.xml.NamespaceContext namespaceContext)
Debugging function for NamespaceContext.

Parameters:
namespaceContext - the namespace context to dump.
Returns:
a string representing the namespace context

createXPath

public static com.ibm.commons.xml.xpath.XPathExpression createXPath(java.lang.String xpathExpr,
                                                                    boolean useCache)
                                                             throws XMLException
Create an XPath expression object. This object can be safetly reused for subsequent evaluations. WARN: This object does not take care of the Document XPath context. To take advantage of this context, use one of the string based functions.

Parameters:
xpathExpr - the xpath expression
useCache - indicate if the xpath should be cached
Returns:
the XPath expression
Throws:
XMLException

createXPath

public static com.ibm.commons.xml.xpath.XPathExpression createXPath(java.lang.String xpathExpr)
                                                             throws XMLException
Create an XPath expression object. This object can be safetly reused for subsequent evaluations. WARN: This object does not take care of the Document XPath context. To take advantage of this context, use one of the string based functions.

Parameters:
xpathExpr - the xpath expression
Returns:
the XPath expression
Throws:
XMLException

evaluateXPath

public static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node,
                                                        java.lang.String xpathExpr,
                                                        com.ibm.commons.xml.NamespaceContext nsContext,
                                                        boolean useCache)
                                                 throws XMLException
Evaluate an XPath expression. This object can be safetly reused for subsequent evaluations.

Parameters:
node - the node source of the XPath
xpathExpr - the xpath expression
nsContext - the namespace context to use by the engine
useCache - indicate if the xpath should be cached
Returns:
the result of the XPath evaluation
Throws:
XMLException

evaluateXPath

public static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node,
                                                        java.lang.String xpathExpr,
                                                        com.ibm.commons.xml.NamespaceContext nsContext)
                                                 throws XMLException
Evaluate an XPath expression. This object can be safetly reused for subsequent evaluations.

Parameters:
node - the node source of the XPath
xpathExpr - the xpath expression
nsContext - the namespace context to use by the engine
Returns:
the result of the XPath evaluation
Throws:
XMLException

evaluateXPath

public static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node,
                                                        java.lang.String xpathExpr)
                                                 throws XMLException
Evaluate an XPath expression. This object can be safetly reused for subsequent evaluations.

Parameters:
node - the node source of the XPath
xpathExpr - the xpath expression
Returns:
the result of the XPath evaluation
Throws:
XMLException

evaluateXPath

public static com.ibm.commons.xml.XResult evaluateXPath(org.w3c.dom.Node node,
                                                        java.lang.String xpathExpr,
                                                        boolean useCache)
                                                 throws XMLException
Evaluate an XPath expression. This object can be safetly reused for subsequent evaluations.

Parameters:
node - the node source of the XPath
xpathExpr - the xpath expression
useCache - indicate if the xpath should be cached
Returns:
the result of the XPath evaluation
Throws:
XMLException

createNodes

public static java.lang.Object createNodes(org.w3c.dom.Node node,
                                           java.lang.String xpathExpr,
                                           boolean useCache)
                                    throws XMLException
Create a node based on an XPath expression object.

Parameters:
node - the node to start from
xpathExpr - the xpath expression
useCache - indicate if the xpath should be cached
Returns:
the XPath expression
Throws:
XMLException

createNodes

public static java.lang.Object createNodes(org.w3c.dom.Node node,
                                           java.lang.String xpathExpr)
                                    throws XMLException
Create a node based on an XPath expression object.

Parameters:
node - the node to start from
xpathExpr - the xpath expression
useCache - indicate if the xpath should be cached
Returns:
the XPath expression
Throws:
XMLException

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document document,
                                                org.w3c.dom.Element parent,
                                                java.lang.String name)
Create an element with the specified name and add it as a child of the specified parent.

Parameters:
document -
parent -
name -
Returns:

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document document,
                                                java.lang.String name)
Create an element with the specified name and add it as a child of the specified parent.

Parameters:
document -
name -
Returns:

nodes

public static java.lang.Object[] nodes(org.w3c.dom.Node node,
                                       java.lang.String xpath)
                                throws XMLException
Evaluate the given XPath expression on the given document, and returns an array with all elements and attributes that match this XPath.

Parameters:
node - the source node
xpath - the XPath to evaluate
Returns:
the array of XML nodes that match the XPath
Throws:
XMLException - if an error occurred

node

public static java.lang.Object node(org.w3c.dom.Node node,
                                    java.lang.String xpath)
                             throws XMLException
Evaluate the given XPath expression on the given document, and returns the first element or attribute that match this XPath.

Parameters:
node - the source node
xpath - the XPath to evaluate
Returns:
the resulting object
Throws:
XMLException - if an error occurred

nodes

public static java.lang.Object[] nodes(org.w3c.dom.Node node,
                                       java.lang.String xpath,
                                       com.ibm.commons.xml.NamespaceContext selectionNS)
                                throws XMLException
Evaluate the given XPath expression on the given document, and returns an array with all elements and attributes that match this XPath.

Parameters:
node - the source node
xpath - the XPath to evaluate
selectionNS - the NamespacContext used to resolve namespaces during XPath evaluation
Returns:
the array of XML nodes that match the XPath
Throws:
XMLException - if an error occurred

node

public static java.lang.Object node(org.w3c.dom.Node node,
                                    java.lang.String xpath,
                                    com.ibm.commons.xml.NamespaceContext selectionNS)
                             throws XMLException
Evaluate the given XPath expression on the given document, and returns the first element or attribute that match this XPath.

Parameters:
node - the source node
xpath - the XPath to evaluate
selectionNS - the NamespacContext used to resolve namespaces during XPath evaluation
Returns:
the resulting object
Throws:
XMLException - if an error occurred

value

public static java.lang.String value(org.w3c.dom.Node node,
                                     java.lang.String xpath)
                              throws XMLException
Get a string value from the first XPath matching element.

Parameters:
node - the source node
xpath - the XPath to evaluate
Returns:
the value as a string
Throws:
XMLException - if an error occurred

value

public static java.lang.String value(org.w3c.dom.Node node,
                                     java.lang.String xpath,
                                     com.ibm.commons.xml.NamespaceContext selectionNS)
                              throws XMLException
Get a string value from the first XPath matching element.

Parameters:
node - the source node
xpath - the XPath to evaluate
selectionNS - the NamespacContext used to resolve namespaces during XPath evaluation
Returns:
the value as a string
Throws:
XMLException - if an error occurred

values

public static java.lang.String[] values(org.w3c.dom.Node node,
                                        java.lang.String xpath)
                                 throws XMLException
Get the string values from the XPath matching elements.

Parameters:
node - the source node
xpath - the XPath to evaluate
Returns:
the values as a string array
Throws:
XMLException - if an error occurred

values

public static java.lang.String[] values(org.w3c.dom.Node node,
                                        java.lang.String xpath,
                                        com.ibm.commons.xml.NamespaceContext selectionNS)
                                 throws XMLException
Get the string values from the XPath matching elements.

Parameters:
node - the source node
xpath - the XPath to evaluate
selectionNS - the NamespacContext used to resolve namespaces during XPath evaluation
Returns:
the values as a string array
Throws:
XMLException - if an error occurred

setValue

public static void setValue(org.w3c.dom.Node node,
                            java.lang.String path,
                            java.lang.String value)
                     throws XMLException
Set the value of the first XPath matching element. That method first evaluates the XPath and, if it returns an existing nodes, then it updates it value. If not, then it tries to add a new node corresponding to that XPath. This operation is possible only if the XPath is simple, thus in a form like node[/node...].

Parameters:
node - the source node
path - the XPath to use
value - the value to set
Throws:
XMLException - if an error occurred

setValue

public static void setValue(org.w3c.dom.Node node,
                            java.lang.String path,
                            java.lang.String value,
                            com.ibm.commons.xml.NamespaceContext selectionNS)
                     throws XMLException
Set the value of the first XPath matching element. That method first evaluates the XPath and, if it returns an existing nodes, then it updates it value. If not, then it tries to add a new node corresponding to that XPath. This operation is possible only if the XPath is simple, thus in a form like node[/node...].

Parameters:
node - the source node
path - the XPath to use
value - the value to set
selectionNS - the NamespacContext used to resolve namespaces during XPath evaluation
Throws:
XMLException - if an error occurred

getFirstElementByName

public static org.w3c.dom.Element getFirstElementByName(org.w3c.dom.Element parent,
                                                        java.lang.String name)
Find a element by name.

Returns:
the element found, or null if it is not available

getFirstElementByNameNS

public static org.w3c.dom.Element getFirstElementByNameNS(org.w3c.dom.Element parent,
                                                          java.lang.String namespaceURI,
                                                          java.lang.String name)
Find a element by name.

Returns:
the element found, or null if it is not available

getElementsByName

public static org.w3c.dom.NodeList getElementsByName(org.w3c.dom.Element parent,
                                                     java.lang.String name)
Find a element by name.

Returns:
the element found, or null if it is not available

getElementsByNameNS

public static org.w3c.dom.NodeList getElementsByNameNS(org.w3c.dom.Element parent,
                                                       java.lang.String namespaceURI,
                                                       java.lang.String name)
Find a element by name.

Returns:
the element found, or null if it is not available

insertAfter

public static org.w3c.dom.Node insertAfter(org.w3c.dom.Node parent,
                                           org.w3c.dom.Node newChild,
                                           org.w3c.dom.Node refChild)
Inserts the node newChild after the existing child node refChild. Inserts the node newChild after the existing child node refChild. If refChild is null, insert newChild at the end of the list of children. If newChild is a DocumentFragment object, all of its children are inserted, in the same order, after refChild. If the newChild is already in the tree, it is first removed.

Returns:
The node being inserted

moveNodeUp

public static boolean moveNodeUp(org.w3c.dom.Node node)
Move an element prior to his previous sibling. If the element doesn't have a previous sibling, then nothing is moved

Parameters:
node - the node to move up
Returns:
true if the element was moved

moveNodeDown

public static boolean moveNodeDown(org.w3c.dom.Node node)
Move an element prior to his previous sibling. If the element doesn't have a previous sibling, then nothing is moved

Parameters:
node - the node to move down
Returns:
true if the element was moved

isNamespaceAttribute

public static boolean isNamespaceAttribute(org.w3c.dom.Attr attribute)
Determines if an Attribute is a namespace attribute.


getAttributeIgnoreCase

public static org.w3c.dom.Attr getAttributeIgnoreCase(org.w3c.dom.Element element,
                                                      java.lang.String attributeName)
Gets the DOM attribute of element with the given name. It returns the first attribute that matches the name, regardless the case. This is particularly useful when dealing with an HTML DOM, as HTML is not case sensitive.

Parameters:
element - the source element
attributeName - the attribute name
Returns:
the XML attribute if any, null otherwise

removeAttributeIgnoreCase

public static void removeAttributeIgnoreCase(org.w3c.dom.Element element,
                                             java.lang.String attributeName)
Removes the DOM attribute from element with the given name. It removes the first attribute that matches the name, regardless the case. This is particularly useful when dealing with an HTML DOM, as HTML is not case sensitive.

Parameters:
element - the source element
attributeName - the attribute name

getAttributeValueIgnoreCase

public static java.lang.String getAttributeValueIgnoreCase(org.w3c.dom.Element element,
                                                           java.lang.String attributeName)
Gets the value of DOM attribute of element with the given name It returns the first attribute value that matches the name, regardless the case. This is particularly useful when dealing with an HTML DOM, as HTML is not case sensitive.

Parameters:
element - the source element
attributeName - the attribute name
Returns:
the XML attribute if any, null otherwise

getOwnerDocument

public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
Return the owner document for the specified node.

Parameters:
node -
Returns:

getNamespacePrefix

public static java.lang.String getNamespacePrefix(org.w3c.dom.Node parentNode,
                                                  java.lang.String preferredPrefix,
                                                  java.lang.String nsUri)
Traverse a node, and parent nodes, for a namespace URI. If the namespace URI is located, the corresponding name is returned. If the namespace uri is not located (i.e., does not exist), it is created as an attribute node of the document root node.

Parameters:
parentNode - - node from which to begin the search
preferredPrefix - - Prefix to use if the namespace attribute must be created.
nsUri - - the namesapce URI to search for
Returns:
the located/created namespace prefix

clone

public static org.w3c.dom.Document clone(org.w3c.dom.Document inDoc)
Clone a Document. This method returns a deep copy of the input Document.

Parameters:
inDoc - the input document
Returns:
the cloned Document

getChildText

public static java.lang.String getChildText(org.w3c.dom.Element element,
                                            java.lang.String nodeName)
Returns the textual content of the named child element, or null if there's no such child. See: org.jdom.Element 'getChildText()'

Parameters:
element - to search for children
Returns:
java.lang.String

getText

public static java.lang.String getText(org.w3c.dom.Node n)
Returns the textual content directly held under this element as a string. The call does not recurse into child elements. If no textual value exists for the element, an empty string is returned.

Parameters:
n -
Returns:

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element e,
                                                 java.lang.String key)
This returns the attribute value for the attribute of the input element with the given name and within no namespace. Returns null if there is no such attribute, and the empty string if the attribute value is empty.

Parameters:
e - the Node
key - the attribute name
Returns:

addNode

public static void addNode(org.w3c.dom.Element parent,
                           java.lang.String elementName)
Add a child element to a parent element. The child element will have the indicated name and default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addNode

public static void addNode(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           java.lang.String namespaceURI)
Add a child element to a parent element. The child element will have the indicated name and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addBigDecimal

public static void addBigDecimal(org.w3c.dom.Element parent,
                                 java.lang.String elementName,
                                 java.math.BigDecimal value)
Add a child element to a parent element. The child element will have the indicated name, BigDecimal value, and a defult (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addBigDecimal

public static void addBigDecimal(org.w3c.dom.Element parent,
                                 java.lang.String elementName,
                                 java.math.BigDecimal value,
                                 java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, BigDecimal value, and a defult (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addBoolean

public static void addBoolean(org.w3c.dom.Element parent,
                              java.lang.String elementName,
                              boolean value)
Add a child element to a parent element. The child element will have the indicated name, boolean value, and namespace. The parent elenent is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addBoolean

public static void addBoolean(org.w3c.dom.Element parent,
                              java.lang.String elementName,
                              boolean value,
                              java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, boolean value, and namespace. The parent elenent is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addDate

public static void addDate(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           java.sql.Date value)
Add a child element to a parent element. The child element will have the indicated name, java.sql.Date value, and the default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addDate

public static void addDate(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           java.sql.Date value,
                           java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, java.sql.Date value, and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addDouble

public static void addDouble(org.w3c.dom.Element parent,
                             java.lang.String elementName,
                             double value)
Add a child element to a parent element. The child element will have the indicated name, double value, and default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addDouble

public static void addDouble(org.w3c.dom.Element parent,
                             java.lang.String elementName,
                             double value,
                             java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, double value, and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addInteger

public static void addInteger(org.w3c.dom.Element parent,
                              java.lang.String elementName,
                              int value)
Add a child element to a parent element. The child element will have the indicated name, int value, and the default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addInteger

public static void addInteger(org.w3c.dom.Element parent,
                              java.lang.String elementName,
                              int value,
                              java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, int value, and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addLong

public static void addLong(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           long value)
Add a child element to a parent element. The child element will have the indicated name, long value, and the default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addLong

public static void addLong(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           long value,
                           java.lang.String namespace)
Add a child element to a parent element. The child element will have the indicated name, long value, and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addString

public static void addString(org.w3c.dom.Element parent,
                             java.lang.String elementName,
                             java.lang.String value)
Add a child element to a parent element. The child element will have the indicated name, String value, and default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addString

public static void addString(org.w3c.dom.Element parent,
                             java.lang.String elementName,
                             java.lang.String value,
                             java.lang.String namespaceURI)
Add a child element to a parent element. The child element will have the indicated name, String value, and namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addTime

public static void addTime(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           java.sql.Time value)
Add a child element to a parent element. The child element will have the indicated name, java.sqlTime value, and default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addTime

public static void addTime(org.w3c.dom.Element parent,
                           java.lang.String elementName,
                           java.sql.Time value,
                           java.lang.String namespaceURI)
Add a child element to a parent element. The child element will have the indicated name, java.sqlTime value, and namespaceURI. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addTimestamp

public static void addTimestamp(org.w3c.dom.Element parent,
                                java.lang.String elementName,
                                java.sql.Timestamp value)
Add a child element to a parent element. The child element will have the indicated name, java.sql.Timestamp value, and default (null) namespace. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

addTimestamp

public static void addTimestamp(org.w3c.dom.Element parent,
                                java.lang.String elementName,
                                java.sql.Timestamp value,
                                java.lang.String namespaceURI)
Add a child element to a parent element. The child element will have the indicated name, java.sql.Timestamp value, and namespaceURI. The parent element is assumed to be attached to a Document.

Parameters:
parent - the parent element
elementName - the Element name
value - the Element value

getChildrenAsList

public static java.util.List<org.w3c.dom.Node> getChildrenAsList(org.w3c.dom.Element elt)
Create a java.util.List contain the child nodes of the specified element.

Parameters:
elt -
Returns:

getSourceReferenceId

public static java.lang.String getSourceReferenceId(org.w3c.dom.Node node)
Return the source reference id for the specified node.

Parameters:
node -
Returns:

getChildElementsByTagNameNS

public static org.w3c.dom.NodeList getChildElementsByTagNameNS(org.w3c.dom.Element element,
                                                               java.lang.String uri,
                                                               java.lang.String tag)
Behaves like getElementsByTagNameNS() but only return nodes that are the children of a specified element.

Parameters:
element - - element to find the children of, may not be null.
uri - - only return children matching this namespace uri.
tag - - only return children matching this tag name.
Returns:
NodeList - matching elements that are children of element.

getChildElementsByTagName

public static org.w3c.dom.NodeList getChildElementsByTagName(org.w3c.dom.Element element,
                                                             java.lang.String tag)
Behaves like getElementsByTagName() but only return nodes that are the children of a specified element.

Parameters:
element - - element to find the children of, may not be null.
tag - - only return children matching this tag name.
Returns:
NodeList - matching elements that are children of element.

compareLocations

public static int compareLocations(org.w3c.dom.Node node1,
                                   int offset1,
                                   org.w3c.dom.Node node2,
                                   int offset2)
compare two nodes. Needed to write my own because of problems in the implementation of the WST Range.compareBoundaryPoints();

Parameters:
node1 -
offset1 -
node2 -
offset2 -
Returns:
less than zero if node1 < nodes2, 0 if node1 == node2, greater than zero if node1 > node2

getNode

public static org.w3c.dom.Node getNode(org.w3c.dom.Node node,
                                       int offset)
Convert the parent, offset into the child node. Node without child are just returned.

Parameters:
node -
offset -
Returns:
Node

getOffsetInParent

public static int getOffsetInParent(org.w3c.dom.Node node)
Helper method to get the offset of a given node with respect to its parent.

Parameters:
node - - may not be null
Returns:
int - zero-based offset of node in its container or -1 if the node as no container.

getAllChildElementsByName

public static org.w3c.dom.NodeList getAllChildElementsByName(org.w3c.dom.Element parent,
                                                             java.lang.String name)
Find all element of a given name that is a child or subchild to n levels of a given parent element. If an a child element has the given tag name, none of its child nodes that may also have that tag name will be added to the NodeList. So essentially only the first child elelent with the given name will be returned from each branch. For example a panel within a panel, only the parent panel would be returned.

Returns:
the elements found, or null if none are found or if there is an error.

concatNodeLists

public static com.ibm.commons.xml.xpath.NodeListImpl concatNodeLists(org.w3c.dom.NodeList nl1,
                                                                     org.w3c.dom.NodeList nl2)
This method will return a nodelist containing all the nodes from 2 given nodeLists.

Parameters:
nl1 -
nl2 -
Returns:

getFirstElementAtAnyDepthByNodeName

public static org.w3c.dom.Element getFirstElementAtAnyDepthByNodeName(org.w3c.dom.Element parent,
                                                                      java.lang.String name)
Find the first element that is a child or subchild under a given Element parent. So essentially returning the first occurance of a given node anywhere in the parent elements child subtree.

Returns:
the element found, or null if it is not available

getChildNodesToNLevels

public static org.w3c.dom.NodeList getChildNodesToNLevels(org.w3c.dom.Node parent)
Find all children and subChildren of the given parent to n sub levels. This will include text nodes!

Returns:
NodeList of all child elements of the parent

findChildAtAnyLevel

public static boolean findChildAtAnyLevel(org.w3c.dom.Node parent,
                                          org.w3c.dom.Node child)
Search through all child nodes and sub child nodes of the given parent node, and return true, if the given child node is ever found.

Returns:
NodeList of all child elements of the parent