public final class XMLUtils extends Object
To read XML data from a source use the parse(...) methods.
To write XML data to a target use the transform(...) methods.
Modifier and Type | Method and Description |
---|---|
static Document |
parse(File file)
Parse the content of the given file as an XML document and return a new
DOM
Document object. |
static void |
parse(File f,
DefaultHandler handler)
Parse the content of the file specified as XML using the specified
DefaultHandler . |
static Document |
parse(InputSource is)
Parse the content of the given input source as an XML document and return
a new DOM
Document object. |
static void |
parse(InputSource is,
DefaultHandler handler)
Parse the content given
InputSource as XML using the
specified DefaultHandler . |
static Document |
parse(InputStream is)
Parse the content of the given
InputStream as an XML
document and return a new DOM Document object. |
static void |
parse(InputStream is,
DefaultHandler handler)
Parse the content of the given
InputStream instance as
XML using the specified DefaultHandler . |
static Document |
parse(InputStream is,
String systemId)
Parse the content of the given
InputStream as an XML
document and return a new DOM Document object. |
static void |
parse(InputStream is,
String systemId,
DefaultHandler handler)
Parse the content of the given
InputStream instance as
XML using the specified DefaultHandler . |
static Document |
parse(String uri)
Parse the content of the given URI as an XML document and return a new
DOM
Document object. |
static void |
parse(String uri,
DefaultHandler handler)
Parse the content described by the giving Uniform Resource Identifier
(URI) as XML using the specified
DefaultHandler . |
static void |
transform(Document doc,
File file)
Transform the document to a file.
|
static void |
transform(Document doc,
OutputStream os)
Transform the document to an output stream.
|
static void |
transform(Document doc,
String uri)
Transform the document to an
URI . |
static void |
transform(Document doc,
Writer writer)
Transform the document to a writer.
|
public static Document parse(File file) throws SAXException, IOException
Document
object. An IllegalArgumentException
is
thrown if the File
is null
null.file
- The file containing the XML to parse.IOException
- If any IO errors occur.SAXException
- If any parse errors occur.IllegalArgumentException
- When f
is null
public static Document parse(InputSource is) throws SAXException, IOException
Document
object. An
IllegalArgumentException
is thrown if the
InputSource
is null
null.is
- InputSource containing the content to be parsed.IOException
- If any IO errors occur.SAXException
- If any parse errors occur.IllegalArgumentException
- When is
is null
public static Document parse(String uri) throws SAXException, IOException
Document
object. An IllegalArgumentException
is
thrown if the URI is null
null.uri
- The location of the content to be parsed.IOException
- If any IO errors occur.SAXException
- If any parse errors occur.IllegalArgumentException
- When uri
is null
public static Document parse(InputStream is) throws SAXException, IOException
InputStream
as an XML
document and return a new DOM Document
object. An
IllegalArgumentException
is thrown if the
InputStream
is null.is
- InputStream containing the content to be parsed.Document
result of parsing the
InputStream
IOException
- If any IO errors occur.SAXException
- If any parse errors occur.IllegalArgumentException
- When is
is null
public static Document parse(InputStream is, String systemId) throws SAXException, IOException
InputStream
as an XML
document and return a new DOM Document
object. An
IllegalArgumentException
is thrown if the
InputStream
is null.is
- InputStream containing the content to be parsed.systemId
- Provide a base for resolving relative URIs.IOException
- If any IO errors occur.SAXException
- If any parse errors occur.IllegalArgumentException
- When is
is null
public static void parse(File f, DefaultHandler handler) throws SAXException, IOException
DefaultHandler
.f
- The file containing the XML to parsehandler
- The SAX DefaultHandler to use.IllegalArgumentException
- If the File object is null.IOException
- If any IO errors occur.SAXException
- If any SAX errors occur during processing.public static void parse(InputSource is, DefaultHandler handler) throws SAXException, IOException
InputSource
as XML using the
specified DefaultHandler
.is
- The InputSource containing the content to be parsed.handler
- The SAX DefaultHandler to use.IllegalArgumentException
- If the InputSource
object is null
.IOException
- If any IO errors occur.SAXException
- If any SAX errors occur during processing.public static void parse(String uri, DefaultHandler handler) throws SAXException, IOException
DefaultHandler
.uri
- The location of the content to be parsed.handler
- The SAX DefaultHandler to use.IllegalArgumentException
- If the uri is null.IOException
- If any IO errors occur.SAXException
- If any SAX errors occur during processing.public static void parse(InputStream is, DefaultHandler handler) throws SAXException, IOException
InputStream
instance as
XML using the specified DefaultHandler
.is
- InputStream containing the content to be parsed.handler
- The SAX DefaultHandler to use.IllegalArgumentException
- If the given InputStream is null.IOException
- If any IO errors occur.SAXException
- If any SAX errors occur during processing.public static void parse(InputStream is, String systemId, DefaultHandler handler) throws SAXException, IOException
InputStream
instance as
XML using the specified DefaultHandler
.is
- InputStream containing the content to be parsed.handler
- The SAX DefaultHandler to use.systemId
- The systemId which is needed for resolving relative URIs.IllegalArgumentException
- If the given InputStream is null.IOException
- If any IO errors occur.SAXException
- If any SAX errors occur during processing.public static void transform(Document doc, File file) throws TransformerException
doc
- The document transform.file
- The target to transform the document toTransformerException
- If an unrecoverable error occurs during the course of the
transformation.public static void transform(Document doc, Writer writer) throws TransformerException
doc
- The document transform.writer
- The target to transform the document toTransformerException
- If an unrecoverable error occurs during the course of the
transformation.public static void transform(Document doc, OutputStream os) throws TransformerException
doc
- The document transform.os
- The target to transform the document toTransformerException
- If an unrecoverable error occurs during the course of the
transformation.public static void transform(Document doc, String uri) throws TransformerException
URI
.doc
- The document transform.uri
- Must be a String that conforms to the URI syntaxTransformerException
- If an unrecoverable error occurs during the course of the
transformation.Copyright © 2003–2021 XDEV Software. All rights reserved.