public class XMLUtils extends Object
Modifier and Type | Field and Description |
---|---|
static DocumentBuilder |
DOCUMENT_BUILDER |
static ThreadLocal<DateFormat> |
XML_TIME_FORMAT
Date format for time type.
|
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static Boolean |
getBooleanAttributeValue(Element element,
String attributeName) |
static Double |
getDoubleAttributeValue(Element element,
String attributeName)
Get a double value from an attribute.
|
static String |
getStringAttributeValue(Element element,
String attributeName) |
static Document |
parse(Reader stream,
Schema schema)
Parse the document from the given stream.
|
static Document |
parseXMLDocument(InputSource xmlDocStream)
Parse xmlDoc an XML document.
|
static Document |
parseXMLDocument(InputStream xmlDocStream)
Parse xmlDoc an XML document.
|
static Document |
parseXMLDocument(Reader xmlDocStream)
Parse xmlDoc an XML document.
|
static void |
writeXML(Document doc,
Writer writer)
Write the document to a writer.
|
static void |
writeXML(Document doc,
Writer writer,
String encoding)
Write the document to a writer.
|
public static final ThreadLocal<DateFormat> XML_TIME_FORMAT
public static final DocumentBuilder DOCUMENT_BUILDER
public static Document parse(Reader stream, Schema schema) throws IOException, SAXException
stream
- a stream containing documentIOException
- if there is an error reading the streamSAXException
- if there is an error parsing the document or it
doesn't match the schemaRuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static Document parseXMLDocument(InputStream xmlDocStream) throws SAXException, IOException
IOException
- if there is an error reading the streamSAXException
- if the document is found to be invalidRuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static Document parseXMLDocument(Reader xmlDocStream) throws SAXException, IOException
IOException
- if there is an error reading the streamSAXException
- if the document is found to be invalidRuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static Document parseXMLDocument(InputSource xmlDocStream) throws SAXException, IOException
IOException
- if there is an error reading the streamSAXException
- if the document is found to be invalidRuntimeException
- if there is an error configuring the XML parser,
this shouldn't happenpublic static String getStringAttributeValue(Element element, String attributeName)
getDoubleAttributeValue(Element, String)
public static Boolean getBooleanAttributeValue(Element element, String attributeName)
getDoubleAttributeValue(Element, String)
public static Double getDoubleAttributeValue(Element element, String attributeName)
element
- the element to get the attribute from, may be nullattributeName
- the attribute name to getpublic static void writeXML(Document doc, Writer writer)
doc
- the document to writewriter
- where to write the documentpublic static void writeXML(Document doc, Writer writer, String encoding)
doc
- the document to writewriter
- where to write the documentencoding
- if non-null use this as the encoding for the textRuntimeException
- if a TransformerException
occurs.