com.ebmwebsourcing.easycommons.xml
Class XMLHelper

java.lang.Object
  extended by com.ebmwebsourcing.easycommons.xml.XMLHelper

public final class XMLHelper
extends java.lang.Object

Utilities methods for XML operations

Author:
Mathieu CARROLLE - EBM WebSourcing, Nicolas Oddoux - EBM WebSourcing

Constructor Summary
XMLHelper()
           
 
Method Summary
static org.w3c.dom.Document createDocumentFromString(java.lang.String xml)
          Create a DOM document from the specified XML string
static java.lang.String createStringFromDOMDocument(org.w3c.dom.Node document)
          Create a String result from a DOM document
static java.lang.String createStringFromDOMNode(org.w3c.dom.Node node)
          Create a String result from a DOM Node
static java.lang.String createStringFromDOMNode(org.w3c.dom.Node node, boolean omitDeclaration)
          Create a String result from a DOM Node
static org.w3c.dom.Node findChild(org.w3c.dom.Node parentNode, java.lang.String namespaceURI, java.lang.String nodeName, boolean recursive)
          Search for the first child of the specified parent node with the specified namespace URI and local name.
static java.lang.String toString(org.w3c.dom.NodeList list)
          Create a String from a Node list
static void writeDocument(org.w3c.dom.Document document, java.io.OutputStream outputStream)
          Write a document to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLHelper

public XMLHelper()
Method Detail

toString

public static final java.lang.String toString(org.w3c.dom.NodeList list)
Create a String from a Node list

Parameters:
list - a node list
Returns:
the string representing the node list

createStringFromDOMDocument

public static final java.lang.String createStringFromDOMDocument(org.w3c.dom.Node document)
                                                          throws javax.xml.transform.TransformerException
Create a String result from a DOM document

Parameters:
document - the DOM Document. It must not be null
Returns:
a String representation of the DOM Document
Throws:
javax.xml.transform.TransformerException - if an unrecoverable error occurs during the course of the transformation
PoolException - This method uses a transformer got from a transformer pool. This unchecked exception is thrown if the current thread waits for a transformer of the pool and is interrupted (as the pool policy is WAIT)

createStringFromDOMNode

public static final java.lang.String createStringFromDOMNode(org.w3c.dom.Node node)
                                                      throws javax.xml.transform.TransformerException
Create a String result from a DOM Node

Parameters:
node - the DOM Node. It must not be null
Returns:
a String representation of the DOM Document
Throws:
javax.xml.transform.TransformerException - if an unrecoverable error occurs during the course of the transformation
PoolException - This method uses a transformer got from a transformer pool. This unchecked exception is thrown if the current thread waits for a transformer of the pool and is interrupted (as the pool policy is WAIT)

createStringFromDOMNode

public static final java.lang.String createStringFromDOMNode(org.w3c.dom.Node node,
                                                             boolean omitDeclaration)
                                                      throws javax.xml.transform.TransformerException
Create a String result from a DOM Node

Parameters:
node - the DOM Node. It must not be null
omitDeclaration - a flag to indicate to omit the XML declaration
Returns:
a String representation of the DOM Document
Throws:
javax.xml.transform.TransformerException - if an unrecoverable error occurs during the course of the transformation
PoolException - This method uses a transformer got from a transformer pool. This unchecked exception is thrown if the current thread waits for a transformer of the pool and is interrupted (as the pool policy is WAIT)

writeDocument

public static final void writeDocument(org.w3c.dom.Document document,
                                       java.io.OutputStream outputStream)
                                throws javax.xml.transform.TransformerException
Write a document to an output stream. The specified output stream and document must not be null.

Parameters:
document - the document to write to the output stream
outputStream - the output stream to write the document
Throws:
javax.xml.transform.TransformerException - if an unrecoverable error occurs during the course of the transformation
PoolException - This method uses a transformer got from a transformer pool. This unchecked exception is thrown if the current thread waits for a transformer of the pool and is interrupted (as the pool policy is WAIT)

createDocumentFromString

public static final org.w3c.dom.Document createDocumentFromString(java.lang.String xml)
                                                           throws org.xml.sax.SAXException,
                                                                  java.io.IOException
Create a DOM document from the specified XML string

Parameters:
xml - a XML string
Returns:
the DOM document representing the specified XML string
Throws:
java.io.IOException - If any IO errors occur
org.xml.sax.SAXException - If any parse errors occur
PoolException - This method uses a document builder got from a document builder pool. This unchecked exception is thrown if the current thread waits for a document builder of the pool and is interrupted (as the pool policy is WAIT)

findChild

public static final org.w3c.dom.Node findChild(org.w3c.dom.Node parentNode,
                                               java.lang.String namespaceURI,
                                               java.lang.String nodeName,
                                               boolean recursive)
Search for the first child of the specified parent node with the specified namespace URI and local name. If recursive, first, search in all the children of first level, then if not found, search in the second level of the first child, ...

Parameters:
parentNode - a parent node
namespaceURI - the namespace URI of the node to search. if null, the namespace is ignored
nodeName - the local name of the node to search
recursive - a flag to know the search is recursive in the XML tree
Returns:
a node if found or null if not found


Copyright © 2012 Petals Link. All Rights Reserved.