com.indexdata.utils
Class XmlUtils

java.lang.Object
  extended by com.indexdata.utils.XmlUtils

public class XmlUtils
extends Object

Some XML helper methods to hide DOM complexity. Uses thread local variables to create Builders once per thread.

Author:
jakub

Method Summary
static Node appendTextNode(Node parent, String tagName, String text)
           
static String escape(String s)
          Escape five, basic XML entities.
static NodeList getNodeList(Object startingPoint, String xPathString)
          Gets a list of nodes by XPath from given starting point
static Document newDoc()
           
static Document newDoc(String rootNode)
           
static Document parse(File file)
           
static Document parse(InputStream source)
           
static Document parse(String uri)
           
static Document parse(StringReader reader)
           
static void serialize(Node doc, OutputStream dest)
           
static void serialize(Node doc, OutputStream dest, Properties props)
           
static void serialize(Node doc, Writer writer)
           
static void serialize(Node doc, Writer writer, Properties props)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newDoc

public static Document newDoc()

newDoc

public static Document newDoc(String rootNode)

parse

public static Document parse(InputStream source)
                      throws SAXException,
                             IOException
Throws:
SAXException
IOException

parse

public static Document parse(String uri)
                      throws SAXException,
                             IOException
Throws:
SAXException
IOException

parse

public static Document parse(StringReader reader)
                      throws SAXException,
                             IOException
Throws:
SAXException
IOException

parse

public static Document parse(File file)
                      throws SAXException,
                             IOException
Throws:
SAXException
IOException

serialize

public static void serialize(Node doc,
                             OutputStream dest)
                      throws TransformerException
Throws:
TransformerException

serialize

public static void serialize(Node doc,
                             Writer writer)
                      throws TransformerException
Throws:
TransformerException

serialize

public static void serialize(Node doc,
                             OutputStream dest,
                             Properties props)
                      throws TransformerException
Throws:
TransformerException

serialize

public static void serialize(Node doc,
                             Writer writer,
                             Properties props)
                      throws TransformerException
Throws:
TransformerException

escape

public static String escape(String s)
Escape five, basic XML entities.

Parameters:
s - string to be escaped
Returns:
xml-escaped string

appendTextNode

public static Node appendTextNode(Node parent,
                                  String tagName,
                                  String text)

getNodeList

public static NodeList getNodeList(Object startingPoint,
                                   String xPathString)
                            throws XPathExpressionException
Gets a list of nodes by XPath from given starting point

Parameters:
startingPoint - The context node
xPathString - The search string
Returns:
The node list found by the XPath
Throws:
StandardServiceException - If XPath evaluation fails.
XPathExpressionException


Copyright © 2012. All Rights Reserved.