com.ebmwebsourcing.easycommons.xml
Class XMLHelper

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

public final class XMLHelper
extends Object

Utilities methods for XML operations

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

Constructor Summary
XMLHelper()
           
 
Method Summary
static Document createDocumentFromString(String xml)
          Create a DOM document from the specified XML string
static String createStringFromDOMDocument(Node document)
          Create a String result from a DOM document
static String createStringFromDOMNode(Node node)
          Create a String result from a DOM Node
static String createStringFromDOMNode(Node node, boolean omitDeclaration)
          Create a String result from a DOM Node
static Node findChild(Node parentNode, String namespaceURI, String nodeName, boolean recursive)
          Search for the first child of the specified parent node with the specified namespace URI and local name.
static String toString(NodeList list)
          Create a String from a Node list
static void writeDocument(Document document, 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 String toString(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 String createStringFromDOMDocument(Node document)
                                                throws TransformerException
Create a String result from a DOM document

Parameters:
document - the DOM Document. It cannot be null
Returns:
a String representation of the DOM Document
Throws:
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 String createStringFromDOMNode(Node node)
                                            throws TransformerException
Create a String result from a DOM Node

Parameters:
node - the DOM Node. It cannot be null
Returns:
a String representation of the DOM Document
Throws:
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 String createStringFromDOMNode(Node node,
                                                   boolean omitDeclaration)
                                            throws TransformerException
Create a String result from a DOM Node

Parameters:
node - the DOM Node. It cannot be null
omitDeclaration - a flag to indicate to omit the XML declaration
Returns:
a String representation of the DOM Document
Throws:
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(Document document,
                                       OutputStream outputStream)
                                throws TransformerException
Write a document to an output stream. The specified output stream and document cannot be null.

Parameters:
document - the document to write to the output stream
outputStream - the output stream to write the document
Throws:
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 Document createDocumentFromString(String xml)
                                               throws SAXException,
                                                      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:
IOException - If any IO errors occur
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 Node findChild(Node parentNode,
                                   String namespaceURI,
                                   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.