ccl.xml
Class XMLUtil

java.lang.Object
  |
  +--ccl.xml.XMLUtil

public class XMLUtil
extends java.lang.Object

This class provides generic helper methods to deal with xml or xslt processing.

Credit: code to escape a string so it can be used as xml text content or an attribute value is taken from the Apache Xerces project.


Method Summary
static java.lang.String escape(char ch)
          If there is a suitable entity reference for this character, return it.
static java.lang.String escape(java.lang.String source)
          Escapes a string so it may be returned as text content or attribute value.
static java.lang.String getValueOf(java.io.File xmlFile, java.lang.String xpath)
          Return the xml value in the given xml file described by the XPath value.
static java.lang.String getValueOf(java.lang.String xmlContent, java.lang.String xpath)
          Return the xml value in the given xml string described by the XPath value.
static java.lang.String getXML(java.io.File xmlFile, java.io.File xsltFile)
          Transforms a given xml content with a given xslt stylesheet file.
static java.lang.String getXML(java.io.File xmlFile, java.lang.String xsltFile)
          Transforms a given xml content with a given xslt stylesheet file.
static java.lang.String getXML(java.lang.String xmlContent, java.io.File xsltFile)
          Transforms a given xml content with a given xslt stylesheet file.
static java.lang.String getXML(java.lang.String xmlContent, java.lang.String xsltContent)
          Transforms a given xml content using the given xslt stylesheet content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

escape

public static java.lang.String escape(char ch)
If there is a suitable entity reference for this character, return it. The list of available entity references is almost but not identical between XML and HTML.


escape

public static java.lang.String escape(java.lang.String source)
Escapes a string so it may be returned as text content or attribute value. Non printable characters are escaped using character references. Where the format specifies a deault entity reference, that reference is used (e.g. <).

Parameters:
source - the string to escape or "" for null.

getXML

public static java.lang.String getXML(java.io.File xmlFile,
                                      java.lang.String xsltFile)
                               throws java.io.IOException,
                                      javax.xml.transform.TransformerException
Transforms a given xml content with a given xslt stylesheet file.

Throws:
java.io.IOException - if the xml file can't be red.
javax.xml.transform.TransformerException - if parsing the xml or xslt data fails.

getXML

public static java.lang.String getXML(java.io.File xmlFile,
                                      java.io.File xsltFile)
                               throws java.io.IOException,
                                      javax.xml.transform.TransformerException
Transforms a given xml content with a given xslt stylesheet file.

Throws:
java.io.IOException - if the xml or xslt file can't be red.
javax.xml.transform.TransformerException - if parsing the xml or xslt data fails.

getXML

public static java.lang.String getXML(java.lang.String xmlContent,
                                      java.io.File xsltFile)
                               throws java.io.IOException,
                                      javax.xml.transform.TransformerException
Transforms a given xml content with a given xslt stylesheet file.

Throws:
java.io.IOException - if the xslt file can't be red.
javax.xml.transform.TransformerException - if parsing the xml or xslt data fails.

getXML

public static java.lang.String getXML(java.lang.String xmlContent,
                                      java.lang.String xsltContent)
                               throws javax.xml.transform.TransformerException
Transforms a given xml content using the given xslt stylesheet content.

Throws:
javax.xml.transform.TransformerException - if parsing the xml or xslt data fails.

getValueOf

public static java.lang.String getValueOf(java.lang.String xmlContent,
                                          java.lang.String xpath)
                                   throws java.lang.Exception
Return the xml value in the given xml string described by the XPath value.

Parameters:
xmlContent - a string with xml data.
xpath - an XPath string describing the location of an xml element.
Returns:
the xml value specified by the XPath parameter.
Throws:
java.lang.Exception - if any parsing error happens.

getValueOf

public static java.lang.String getValueOf(java.io.File xmlFile,
                                          java.lang.String xpath)
                                   throws java.lang.Exception
Return the xml value in the given xml file described by the XPath value.

Parameters:
xmlFile - a file with xml data.
xpath - an XPath string describing the location of an xml element.
Returns:
the xml value specified by the XPath parameter.
Throws:
java.lang.Exception - if any parsing error happens.