net.sourceforge.atunes.kernel.utils
Class XMLUtils

java.lang.Object
  extended by net.sourceforge.atunes.kernel.utils.XMLUtils

public class XMLUtils
extends java.lang.Object

Utility methods for XML.


Constructor Summary
XMLUtils()
           
 
Method Summary
static org.w3c.dom.Node evaluateXPathExpressionAndReturnNode(java.lang.String expression, org.w3c.dom.Node node)
          Evaluates a XPath expression from a XML node, returning a Node object.
static org.w3c.dom.NodeList evaluateXPathExpressionAndReturnNodeList(java.lang.String expression, org.w3c.dom.Node node)
          Evaluates a XPath expression from a XML node, returning a NodeList.
static java.lang.String getAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
          Returns the value of an attribute of a given XML element.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element, java.lang.String tagName)
          Returns a child element with a given name from an XML element.
static java.lang.String getChildElementContent(org.w3c.dom.Element element, java.lang.String tagName)
          Returns value of a child element from a given XML element.
static org.w3c.dom.Document getXMLDocument(java.lang.String xml)
          Returns a XML Document object from an XML String.
static java.lang.Object readBeanFromFile(java.lang.String filename)
          Reads an object from an XML file.
static java.lang.Object readObjectFromFile(java.lang.String filename)
          Reads an object from a file as xml.
static java.lang.Object readObjectFromString(java.lang.String string)
          Reads an object from a String as xml.
static void writeBeanToFile(java.lang.Object bean, java.lang.String filename)
          Writes an object to an XML file.
static void writeObjectToFile(java.lang.Object object, java.lang.String filename)
          Writes an object to a file as xml.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

evaluateXPathExpressionAndReturnNode

public static org.w3c.dom.Node evaluateXPathExpressionAndReturnNode(java.lang.String expression,
                                                                    org.w3c.dom.Node node)
Evaluates a XPath expression from a XML node, returning a Node object.

Parameters:
expression - A XPath expression
node - The Node for which this expression should be evaluated
Returns:
The result od evaluating the XPath expression to the given Node or null if an ecxception occured

evaluateXPathExpressionAndReturnNodeList

public static org.w3c.dom.NodeList evaluateXPathExpressionAndReturnNodeList(java.lang.String expression,
                                                                            org.w3c.dom.Node node)
Evaluates a XPath expression from a XML node, returning a NodeList.

Parameters:
expression - A XPath expression
node - The NodeList for which this expression should be evaluated
Returns:
The result od evaluating the XPath expression to the given or null if an ecxception occured NodeList

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element element,
                                                 java.lang.String attributeName)
Returns the value of an attribute of a given XML element.

Parameters:
element - A element
attributeName - The name of the attribute
Returns:
The value of the attribute or null if no such attribute exists

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element,
                                                  java.lang.String tagName)
Returns a child element with a given name from an XML element.

Parameters:
element - A Element
tagName - The name of the child element
Returns:
The child element or null if no such child exists

getChildElementContent

public static java.lang.String getChildElementContent(org.w3c.dom.Element element,
                                                      java.lang.String tagName)
Returns value of a child element from a given XML element.

Parameters:
element - A Elemnt
tagName - The name of the child elment
Returns:
The value of the child element

getXMLDocument

public static org.w3c.dom.Document getXMLDocument(java.lang.String xml)
Returns a XML Document object from an XML String.

Parameters:
xml - The String that should be parsed to an XML document
Returns:
The parsed XML document or null if the String couldn't be parsed

readBeanFromFile

public static java.lang.Object readBeanFromFile(java.lang.String filename)
                                         throws java.io.IOException
Reads an object from an XML file.

Parameters:
filename - the filename
Returns:
the object
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readObjectFromFile

public static java.lang.Object readObjectFromFile(java.lang.String filename)
                                           throws java.io.IOException
Reads an object from a file as xml.

Parameters:
filename - filename
Returns:
The object read from the xml file
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readObjectFromString

public static java.lang.Object readObjectFromString(java.lang.String string)
Reads an object from a String as xml.

Parameters:
string - the string
Returns:
The object read from the xml string

writeBeanToFile

public static void writeBeanToFile(java.lang.Object bean,
                                   java.lang.String filename)
                            throws java.io.IOException
Writes an object to an XML file.

Parameters:
bean - the bean
filename - the filename
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeObjectToFile

public static void writeObjectToFile(java.lang.Object object,
                                     java.lang.String filename)
                              throws java.io.IOException
Writes an object to a file as xml.

Parameters:
object - Object that should be writen to a xml file
filename - filename
Throws:
java.io.IOException - Signals that an I/O exception has occurred.


Copyright © 2006-2008 The aTunes Team. All Rights Reserved.