net.sourceforge.ajaxtags.helpers
Class XMLUtils

java.lang.Object
  extended by net.sourceforge.ajaxtags.helpers.XMLUtils

public final class XMLUtils
extends Object

Some helper functions for XML.


Method Summary
static Document createDocument()
          Create a new Document.
static NodeList evaluateXPathExpression(String expression, Node node)
          Evaluate XPath expression and return list of nodes.
static Object evaluateXPathExpression(String expression, Node node, QName returnValue)
          Evaluate XPath expression.
static String format(String xml)
          Parse string as XML document and return string with reformatted document.
static XPath getNewXPath()
          Create and return a new XPath object from ThreadLocal.
static Document getXMLDocument(String xml)
          Parse string with XML content to Document.
static String toString(Document document)
          Transform document to string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

evaluateXPathExpression

public static NodeList evaluateXPathExpression(String expression,
                                               Node node)
                                        throws XPathExpressionException
Evaluate XPath expression and return list of nodes.

Parameters:
expression - XPath expression
node - DOM node
Returns:
list of DOM nodes
Throws:
XPathExpressionException - if expression cannot be evaluated

evaluateXPathExpression

public static Object evaluateXPathExpression(String expression,
                                             Node node,
                                             QName returnValue)
                                      throws XPathExpressionException
Evaluate XPath expression.

Parameters:
expression - XPath expression
node - DOM node
returnValue - the desired return type
Returns:
result of evaluating an XPath expression as an Object of returnType
Throws:
XPathExpressionException - if expression cannot be evaluated

getNewXPath

public static XPath getNewXPath()
Create and return a new XPath object from ThreadLocal.

Returns:
a new XPath object.

getXMLDocument

public static Document getXMLDocument(String xml)
                               throws SAXException
Parse string with XML content to Document.

Parameters:
xml - string with XML content
Returns:
Document
Throws:
SAXException - if any parse errors occur

createDocument

public static Document createDocument()
                               throws ParserConfigurationException
Create a new Document.

Returns:
an empty document
Throws:
ParserConfigurationException - if a DocumentBuilder cannot be created

format

public static String format(String xml)
                     throws TransformerException,
                            SAXException
Parse string as XML document and return string with reformatted document.

Parameters:
xml - string with XML content
Returns:
reformatted content
Throws:
TransformerException - if it is not possible to transform document to string
SAXException - if any parse errors occur

toString

public static String toString(Document document)
                       throws TransformerException
Transform document to string representation.

Parameters:
document - XHTML document
Returns:
string representation of document
Throws:
TransformerException - if it is not possible to create a Transformer instance or to transform document


Copyright © 2005-2010 The Ajaxtags Team. All Rights Reserved.