public class XMLUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static javax.xml.parsers.DocumentBuilder |
DOCUMENT_BUILDER |
static org.xml.sax.ErrorHandler |
STANDARD_ERROR_HANDLER
Standard error handler that throws exceptions on error and fatalError and
logs a warning on warning.
|
static java.lang.ThreadLocal<java.text.DateFormat> |
XML_TIME_FORMAT
Date format for time type.
|
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
compareDocuments(org.w3c.dom.Document controlDoc,
org.w3c.dom.Document testDoc)
Compare two documents and check if they are the same or not.
|
static java.lang.Boolean |
getBooleanAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName) |
static java.lang.Double |
getDoubleAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName)
Get a double value from an attribute.
|
static java.lang.String |
getStringAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName) |
static org.w3c.dom.Document |
parse(java.io.Reader stream,
javax.xml.validation.Schema schema)
Parse the document from the given stream.
|
static org.w3c.dom.Document |
parseXMLDocument(org.xml.sax.InputSource xmlDocStream)
Parse xmlDoc an XML document.
|
static org.w3c.dom.Document |
parseXMLDocument(java.io.InputStream xmlDocStream)
Parse xmlDoc an XML document.
|
static org.w3c.dom.Document |
parseXMLDocument(java.io.Reader xmlDocStream)
Parse xmlDoc an XML document.
|
static void |
writeXML(org.w3c.dom.Document doc,
java.io.Writer writer)
Write the document to a writer.
|
static void |
writeXML(org.w3c.dom.Document doc,
java.io.Writer writer,
java.lang.String encoding)
Write the document to a writer.
|
public static final java.lang.ThreadLocal<java.text.DateFormat> XML_TIME_FORMAT
public static final javax.xml.parsers.DocumentBuilder DOCUMENT_BUILDER
public static final org.xml.sax.ErrorHandler STANDARD_ERROR_HANDLER
public static org.w3c.dom.Document parse(java.io.Reader stream, javax.xml.validation.Schema schema) throws java.io.IOException, org.xml.sax.SAXException
stream
- a stream containing documentjava.io.IOException
- if there is an error reading the streamorg.xml.sax.SAXException
- if there is an error parsing the document or it
doesn't match the schemajava.lang.RuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static org.w3c.dom.Document parseXMLDocument(java.io.InputStream xmlDocStream) throws org.xml.sax.SAXException, java.io.IOException
java.io.IOException
- if there is an error reading the streamorg.xml.sax.SAXException
- if the document is found to be invalidjava.lang.RuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static org.w3c.dom.Document parseXMLDocument(java.io.Reader xmlDocStream) throws org.xml.sax.SAXException, java.io.IOException
java.io.IOException
- if there is an error reading the streamorg.xml.sax.SAXException
- if the document is found to be invalidjava.lang.RuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static org.w3c.dom.Document parseXMLDocument(org.xml.sax.InputSource xmlDocStream) throws org.xml.sax.SAXException, java.io.IOException
java.io.IOException
- if there is an error reading the streamorg.xml.sax.SAXException
- if the document is found to be invalidjava.lang.RuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static java.lang.String getStringAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
getDoubleAttributeValue(Element, String)
public static java.lang.Boolean getBooleanAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
getDoubleAttributeValue(Element, String)
public static java.lang.Double getDoubleAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
element
- the element to get the attribute from, may be nullattributeName
- the attribute name to getpublic static void writeXML(org.w3c.dom.Document doc, java.io.Writer writer)
doc
- the document to writewriter
- where to write the documentpublic static void writeXML(org.w3c.dom.Document doc, java.io.Writer writer, java.lang.String encoding)
doc
- the document to writewriter
- where to write the documentencoding
- if non-null use this as the encoding for the textjava.lang.RuntimeException
- if a TransformerException
occurs.public static boolean compareDocuments(org.w3c.dom.Document controlDoc, org.w3c.dom.Document testDoc)
controlDoc
- testDoc
-