Milyn-Commons Version 0.6

org.milyn.xml
Class XmlUtil

java.lang.Object
  extended byorg.milyn.xml.XmlUtil

public class XmlUtil
extends java.lang.Object

XMl utility methods.

Author:
Tom Fennelly

Constructor Summary
XmlUtil()
           
 
Method Summary
static org.w3c.dom.Node getNode(org.w3c.dom.Node node, java.lang.String xpath)
          Get the W3C Node instance associated with the XPath selection supplied.
static org.w3c.dom.NodeList getNodeList(org.w3c.dom.Node node, java.lang.String xpath)
          Get the W3C NodeList instance associated with the XPath selection supplied.
static java.lang.String getString(org.w3c.dom.Node node, java.lang.String xpath)
          Get the String data associated with the XPath selection supplied.
static boolean isTextNode(org.w3c.dom.Node node)
          Is the supplied W3C DOM Node a text node.
static org.w3c.dom.Document parseStream(java.io.InputStream stream, boolean validate)
          Parse the XML stream and return the associated W3C Document object.
static org.w3c.dom.Document parseStream(java.io.InputStream stream, org.xml.sax.EntityResolver entityResolver, boolean validate)
          Parse the XML stream and return the associated W3C Document object.
static void removeEntities(java.io.Reader reader, java.io.Writer writer)
          Remove all entities from the supplied Reader stream replacing them with their actual character values.
static java.lang.String removeEntities(java.lang.String string)
          Remove all entities from the supplied String stream replacing them with there actual character values.
static void rewriteEntities(java.io.Reader reader, java.io.Writer writer)
          Rewrite all entities from the supplied Reader stream replacing them with their character reference equivalents.
static java.lang.String serialize(org.w3c.dom.NodeList nodeList)
          Serialise the supplied W3C DOM subtree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

removeEntities

public static void removeEntities(java.io.Reader reader,
                                  java.io.Writer writer)
                           throws java.io.IOException
Remove all entities from the supplied Reader stream replacing them with their actual character values.

Both the read and write streams are returned unclosed.

Parameters:
reader - The read stream.
writer - The write stream.
Throws:
java.io.IOException

removeEntities

public static java.lang.String removeEntities(java.lang.String string)
Remove all entities from the supplied String stream replacing them with there actual character values.

Parameters:
string - The string on which the operation is to be carried out.
Returns:
The string with its entities rewriten.

rewriteEntities

public static void rewriteEntities(java.io.Reader reader,
                                   java.io.Writer writer)
                            throws java.io.IOException
Rewrite all entities from the supplied Reader stream replacing them with their character reference equivalents.

Example:   is rewriten as  

Both the read and write streams are returned unclosed.

Parameters:
reader - The read stream.
writer - The write stream.
Throws:
java.io.IOException

parseStream

public static org.w3c.dom.Document parseStream(java.io.InputStream stream,
                                               boolean validate)
                                        throws org.xml.sax.SAXException,
                                               java.io.IOException
Parse the XML stream and return the associated W3C Document object.

Parameters:
stream - The stream to be parsed.
validate - True if the document is to be validated, otherwise false.
Returns:
The W3C Document object associated with the input stream.
Throws:
org.xml.sax.SAXException
java.io.IOException

parseStream

public static org.w3c.dom.Document parseStream(java.io.InputStream stream,
                                               org.xml.sax.EntityResolver entityResolver,
                                               boolean validate)
                                        throws org.xml.sax.SAXException,
                                               java.io.IOException
Parse the XML stream and return the associated W3C Document object.

Parameters:
stream - The stream to be parsed.
entityResolver - Entity resolver to be used during the parse.
validate - True if the document is to be validated, otherwise false.
Returns:
The W3C Document object associated with the input stream.
Throws:
org.xml.sax.SAXException
java.io.IOException

getNodeList

public static org.w3c.dom.NodeList getNodeList(org.w3c.dom.Node node,
                                               java.lang.String xpath)
Get the W3C NodeList instance associated with the XPath selection supplied.

Parameters:
node - The document node to be searched.
xpath - The XPath String to be used in the selection.
Returns:
The W3C NodeList instance at the specified location in the document, or null.

getNode

public static org.w3c.dom.Node getNode(org.w3c.dom.Node node,
                                       java.lang.String xpath)
Get the W3C Node instance associated with the XPath selection supplied.

Parameters:
node - The document node to be searched.
xpath - The XPath String to be used in the selection.
Returns:
The W3C Node instance at the specified location in the document, or null.

getString

public static java.lang.String getString(org.w3c.dom.Node node,
                                         java.lang.String xpath)
Get the String data associated with the XPath selection supplied.

Parameters:
xpath - The XPath String to be used in the selection.
Returns:
The string data located at the specified location in the document, or an empty string for an empty resultset query.

serialize

public static java.lang.String serialize(org.w3c.dom.NodeList nodeList)
                                  throws org.w3c.dom.DOMException
Serialise the supplied W3C DOM subtree.

Parameters:
nodeList - The DOM subtree as a NodeList.
Returns:
The subtree in serailised form.
Throws:
org.w3c.dom.DOMException - Unable to serialise the DOM.

isTextNode

public static boolean isTextNode(org.w3c.dom.Node node)
Is the supplied W3C DOM Node a text node.

Parameters:
node - The node to be tested.
Returns:
True if the node is a text node, otherwise false.

Milyn-Commons Version 0.6