maito.util
Class XMLTools

java.lang.Object
  extended by maito.util.XMLTools

public class XMLTools
extends java.lang.Object

This class that holds a couple of useful methods for accessing xml data and writing an xml document to a file. This class is NOT an all purpose xml utility kit. The methods that are included are designed only to be used by this program.

Author:
Antti Laitinen

Method Summary
static java.lang.String[] getAllContents(javax.xml.parsers.DocumentBuilder builder, java.io.InputStream xml, java.lang.String xpathExpression)
          Returns the text content of one or more elements in an XML document.
static java.lang.String getNodeContent(javax.xml.parsers.DocumentBuilder builder, java.io.InputStream xml, java.lang.String xpathExpression)
          Returns the text content of an element in an XML document.
static java.io.File writeDocumentToFile(org.w3c.dom.Document doc, java.lang.String filename)
          Writes a document to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNodeContent

public static java.lang.String getNodeContent(javax.xml.parsers.DocumentBuilder builder,
                                              java.io.InputStream xml,
                                              java.lang.String xpathExpression)
                                       throws java.io.IOException,
                                              org.xml.sax.SAXException,
                                              javax.xml.xpath.XPathExpressionException
Returns the text content of an element in an XML document.

Parameters:
builder - Used in building a org.w3c.dom.Document object.
xml - Must be an InputStream which contains a valid xml document.
xpathExpression - An XPath expression which determines the target node in the document
Returns:
The content of the node as a string. null if the value or node is not available.
Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.xpath.XPathExpressionException

getAllContents

public static java.lang.String[] getAllContents(javax.xml.parsers.DocumentBuilder builder,
                                                java.io.InputStream xml,
                                                java.lang.String xpathExpression)
                                         throws java.io.IOException,
                                                org.xml.sax.SAXException,
                                                javax.xml.xpath.XPathExpressionException
Returns the text content of one or more elements in an XML document. If the given XPath expression matches more that one node then contents from all nodes are returned.

Parameters:
builder - Used in building a org.w3c.dom.Document object.
xml - Must be an InputStream which contains a valid xml document.
xpathExpression - An XPath expression which determines the target node(s) in the document.
Returns:
The contents of all matching nodes as String[]. null if no match is found.
Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.xpath.XPathExpressionException

writeDocumentToFile

public static java.io.File writeDocumentToFile(org.w3c.dom.Document doc,
                                               java.lang.String filename)
Writes a document to a file. NOTE: writing attributes is NOT supported!

Parameters:
doc -
filename -
Returns: