xmlwise
Class Xmlwise

java.lang.Object
  extended by xmlwise.Xmlwise

public class Xmlwise
extends java.lang.Object

Xmlwise convenience methods for loading xml documents and render them into XmlElement trees.

Author:
Christoffer Lerno

Method Summary
static org.w3c.dom.Document createDocument(java.lang.String xml)
          Creates a DOM Document from the specified XML string, ignoring DTD-validation.
static org.w3c.dom.Document createDocument(java.lang.String xml, boolean validate, boolean loadExternalDTD)
          Creates a DOM Document from the specified XML string, ignoring DTD-validation.
static XmlElement createXml(java.lang.String xml)
          Creates a document from a string and transforms it into an XmlElement tree.
static java.lang.String escapeXML(java.lang.String stringToEscape)
          Escapes a string to be used in an xml document.
static org.w3c.dom.Document loadDocument(java.io.File file)
          Loads an XML document ignoring DTD-validation.
static org.w3c.dom.Document loadDocument(java.io.File file, boolean validate, boolean loadExternalDTD)
          Loads an XML document.
static XmlElement loadXml(java.io.File file)
          Loads a document from file and transforms it into an XmlElement tree.
static XmlElement loadXml(java.lang.String filename)
          Loads a document from file and transforms it into an XmlElement tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadDocument

public static org.w3c.dom.Document loadDocument(java.io.File file)
                                         throws java.io.IOException,
                                                XmlParseException
Loads an XML document ignoring DTD-validation.

Parameters:
file - the file to read from.
Returns:
an XML document.
Throws:
java.io.IOException - if we fail to load the file.
XmlParseException - if there is a problem parsing the xml in the file.

loadDocument

public static org.w3c.dom.Document loadDocument(java.io.File file,
                                                boolean validate,
                                                boolean loadExternalDTD)
                                         throws java.io.IOException,
                                                XmlParseException
Loads an XML document.

Parameters:
file - the file to read from.
validate - if we should validate the document or not.
loadExternalDTD - true to allow loading of external dtds.
Returns:
an XML document.
Throws:
java.io.IOException - if we fail to load the file.
XmlParseException - if there is a problem parsing the xml in the file.

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xml,
                                                  boolean validate,
                                                  boolean loadExternalDTD)
                                           throws XmlParseException
Creates a DOM Document from the specified XML string, ignoring DTD-validation.

Parameters:
xml - a valid XML document, ie the String can't be null or empty
validate - if we should validate the document or not.
loadExternalDTD - true to allow loading of external dtds.
Returns:
the Document object for the specified string.
Throws:
XmlParseException - if we fail to parse the XML.

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xml)
                                           throws XmlParseException
Creates a DOM Document from the specified XML string, ignoring DTD-validation.

Parameters:
xml - a valid XML document, ie the String can't be null or empty
Returns:
the Document object for the specified string.
Throws:
XmlParseException - if we fail to parse the XML.

escapeXML

public static java.lang.String escapeXML(java.lang.String stringToEscape)
Escapes a string to be used in an xml document.

The following replacements are made:

<&lt;
>&gt;
&&amp;
"&quot;
'&apos;

Parameters:
stringToEscape - the string to escape.
Returns:
an escaped string suitable for use in an xml document.

loadXml

public static XmlElement loadXml(java.io.File file)
                          throws XmlParseException,
                                 java.io.IOException
Loads a document from file and transforms it into an XmlElement tree.

Parameters:
file - the file to load.
Returns:
an XmlElement tree rendered from the file.
Throws:
XmlParseException - if parsing the file failed for some reason.
java.io.IOException - if there were any problems reading from the file.

loadXml

public static XmlElement loadXml(java.lang.String filename)
                          throws XmlParseException,
                                 java.io.IOException
Loads a document from file and transforms it into an XmlElement tree.

Parameters:
filename - the path to the file.
Returns:
an XmlElement tree rendered from the file.
Throws:
XmlParseException - if parsing the file failed for some reason.
java.io.IOException - if there were any problems reading from the file.

createXml

public static XmlElement createXml(java.lang.String xml)
                            throws XmlParseException
Creates a document from a string and transforms it into an XmlElement tree.

Parameters:
xml - the xml as a string.
Returns:
an XmlElement tree rendered from the file.
Throws:
XmlParseException - if parsing the xml failed to validate for some reason.