nu.staldal.xtree
Class XTreeUtil

java.lang.Object
  extended by nu.staldal.xtree.XTreeUtil

public final class XTreeUtil
extends java.lang.Object

Some utility methods for XTree. All methods in this class are static.


Method Summary
static Element parseXML(org.xml.sax.InputSource xmlInput, boolean validateDTD, java.lang.String schemaType, org.xml.sax.InputSource schema)
          Parse an XML document into an XTree.
static Element parseXMLSequential(org.xml.sax.InputSource xmlInput, boolean validateDTD, java.lang.String schemaType, org.xml.sax.InputSource schema, ElementHandler handler)
          Parse an XML document into a list of XTree:s, one for each element under the root.
static void serialize(Node tree, java.io.OutputStream os)
          Serialize an XTree into an OutputStream.
static void serialize(Node tree, java.io.OutputStream os, java.util.Properties prop)
          Serialize an XTree into an OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseXML

public static Element parseXML(org.xml.sax.InputSource xmlInput,
                               boolean validateDTD,
                               java.lang.String schemaType,
                               org.xml.sax.InputSource schema)
                        throws org.xml.sax.SAXParseException,
                               org.xml.sax.SAXException,
                               java.io.IOException
Parse an XML document into an XTree. Uses JAXP to find a parser and JARV to find a validator. Will not support xml:base.

Parameters:
xmlInput - the input to parse
validateDTD - validate using DTD
schemaType - the type of schema to use, or null for no schema validation
schema - the schema to use, or null for no schema validation
Returns:
an XTree representation of the XML data
Throws:
org.xml.sax.SAXParseException - if the XML data is not valid
org.xml.sax.SAXException - if any other error occurs while parsing the XML data
java.io.IOException - if there was some I/O error while reading the input.

parseXMLSequential

public static Element parseXMLSequential(org.xml.sax.InputSource xmlInput,
                                         boolean validateDTD,
                                         java.lang.String schemaType,
                                         org.xml.sax.InputSource schema,
                                         ElementHandler handler)
                                  throws org.xml.sax.SAXParseException,
                                         org.xml.sax.SAXException,
                                         java.io.IOException
Parse an XML document into a list of XTree:s, one for each element under the root. Uses JAXP to find a parser and JARV to find a validator. Will not support xml:base.

Parameters:
xmlInput - the input to parse
validateDTD - validate using DTD
schemaType - the type of schema to use, or null for no schema validation
schema - the schema to use, or null for no schema validation
handler - handler to invoke for each element
Returns:
the root element (without any children)
Throws:
org.xml.sax.SAXParseException - if the XML data is not valid
org.xml.sax.SAXException - if any other error occurs while parsing the XML data
java.io.IOException - if there was some I/O error while reading the input.

serialize

public static void serialize(Node tree,
                             java.io.OutputStream os)
                      throws java.io.IOException
Serialize an XTree into an OutputStream.

Parameters:
tree - the XTree to serialize
os - the OutputStream to write to
Throws:
java.io.IOException - if any error occurs

serialize

public static void serialize(Node tree,
                             java.io.OutputStream os,
                             java.util.Properties prop)
                      throws java.io.IOException
Serialize an XTree into an OutputStream.

Parameters:
tree - the XTree to serialize
os - the OutputStream to write to
prop - output properties
Throws:
java.io.IOException - if any error occurs