biweekly.util
Class XmlUtils

java.lang.Object
  extended by biweekly.util.XmlUtils

public class XmlUtils
extends Object

Generic XML utility methods.

Author:
Michael Angstadt

Method Summary
static Document createDocument()
          Creates a new XML document.
static Element getFirstChildElement(Element parent)
          Gets the first child element of an element.
static Element getRootElement(Document parent)
          Gets the root element of a document.
static Document toDocument(Reader reader)
          Parses an XML document from a reader.
static Document toDocument(String xml)
          Parses an XML string into a DOM.
static List<Element> toElementList(NodeList nodeList)
          Gets all the elements out of a NodeList.
static String toString(Node node)
          Converts an XML node to a string.
static String toString(Node node, Map<String,String> outputProperties)
          Converts an XML node to a string.
static void toWriter(Node node, Writer writer)
          Writes an XML node to a writer.
static void toWriter(Node node, Writer writer, Map<String,String> outputProperties)
          Writes an XML node to a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDocument

public static Document createDocument()
Creates a new XML document.

Returns:
the XML document

toDocument

public static Document toDocument(String xml)
                           throws SAXException
Parses an XML string into a DOM.

Parameters:
xml - the XML string
Returns:
the parsed DOM
Throws:
SAXException - if the string is not valid XML

toDocument

public static Document toDocument(Reader reader)
                           throws SAXException,
                                  IOException
Parses an XML document from a reader.

Parameters:
reader - the reader
Returns:
the parsed DOM
Throws:
SAXException - if the XML is not valid
IOException - if there is a problem reading from the reader

toString

public static String toString(Node node)
Converts an XML node to a string.

Parameters:
node - the XML node
Returns:
the string

toString

public static String toString(Node node,
                              Map<String,String> outputProperties)
Converts an XML node to a string.

Parameters:
node - the XML node
outputProperties - the output properties
Returns:
the string

toWriter

public static void toWriter(Node node,
                            Writer writer)
                     throws TransformerException
Writes an XML node to a writer.

Parameters:
node - the XML node
writer - the writer
Throws:
TransformerException - if there's a problem writing to the writer

toWriter

public static void toWriter(Node node,
                            Writer writer,
                            Map<String,String> outputProperties)
                     throws TransformerException
Writes an XML node to a writer.

Parameters:
node - the XML node
writer - the writer
outputProperties - the output properties
Throws:
TransformerException - if there's a problem writing to the writer

toElementList

public static List<Element> toElementList(NodeList nodeList)
Gets all the elements out of a NodeList.

Parameters:
nodeList - the node list
Returns:
the elements

getRootElement

public static Element getRootElement(Document parent)
Gets the root element of a document.

Parameters:
parent - the document
Returns:
the root element

getFirstChildElement

public static Element getFirstChildElement(Element parent)
Gets the first child element of an element.

Parameters:
parent - the parent element
Returns:
the first child element or null if there are no child elements


Copyright © 2013 Michael Angstadt. All Rights Reserved.