public final class XMLUtils extends Object
This class cannot be instantiated or subclassed by clients.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ENCODING
The XML default encoding to use, which is
"UTF-8" . |
static String |
OPTION_DECLARE_XML
Option to determine whether to put the XML declaration on top of the serialized XML stream.
|
static String |
OPTION_ENCODING
Options to specify the XML encoding to use.
|
static String |
OPTION_FORMATTED
Option to determine whether to format an XML serialization.
|
static String |
OPTION_INDENT_STRING
Option to specify the indentation String to use.
|
static String |
OPTION_NEW_LINE
Option to specify the line separator to use when serializing XML streams.
|
static String |
OPTION_USE_BUFFERED_WRITER
Option to determine whether to use a buffered stream when serializing an XML stream.
|
Modifier and Type | Method and Description |
---|---|
static CoreException |
createCoreException(SAXException e)
Creates a
CoreException based on the specified XML exception. |
static XMLWriter |
createWriter(File file)
Creates a new
XMLWriter instance for the specified file, using the default XML encoding. |
static XMLWriter |
createWriter(OutputStream os,
boolean useBuffer)
Creates a new
XMLWriter instance for the specified output stream, using the default XML encoding. |
static XMLWriter |
createWriter(OutputStream os,
Map<?,?> options)
Creates a new
XMLWriter instance for the specified output stream, using the serialization options. |
static XMLWriter |
createWriter(Writer writer,
boolean useBuffer)
Creates a new
XMLWriter instance for the specified writer. |
static XMLWriter |
createWriter(Writer writer,
Map<?,?> options)
Creates a new
XMLWriter instance for the specified writer, using the serialization options. |
static SAXParser |
newParser()
Creates a new
SAXParser parser instance. |
public static final String OPTION_ENCODING
public static final String OPTION_NEW_LINE
\n
.public static final String OPTION_FORMATTED
public static final String OPTION_DECLARE_XML
public static final String OPTION_INDENT_STRING
public static final String OPTION_USE_BUFFERED_WRITER
public static final String DEFAULT_ENCODING
"UTF-8"
.public static SAXParser newParser() throws SAXException
SAXParser
parser instance.
You should then register to this parser a subclass of XMLDefaultHandler
as content handler.
SAXException
- if an XML parser can't be provided.XMLDefaultHandler
public static XMLWriter createWriter(File file) throws IOException
XMLWriter
instance for the specified file, using the default XML encoding.file
- the output location where to write XML data.IOException
- if the file could not be opened for write.DEFAULT_ENCODING
public static XMLWriter createWriter(OutputStream os, boolean useBuffer) throws IOException
XMLWriter
instance for the specified output stream, using the default XML encoding.
You can specify whether the platform must use buffering on top of the provided output stream. It is recommended to use buffering, unless the specified output stream internally already uses buffers.
os
- the output location where to write XML data.useBuffer
- true
if the buffering must be used.IOException
- if the file could not be opened for write.DEFAULT_ENCODING
public static XMLWriter createWriter(OutputStream os, Map<?,?> options) throws IOException
XMLWriter
instance for the specified output stream, using the serialization options.os
- the output location where to write XML data.options
- the options to control the XML serialization.IOException
- if the file could not be opened for write.public static XMLWriter createWriter(Writer writer, boolean useBuffer) throws IOException
XMLWriter
instance for the specified writer.
You can specify whether the platform must use buffering on top of the provided writer. It is recommended to use buffering, unless the specified writer internally already uses buffers.
writer
- the writer where to write XML data.useBuffer
- true
if the buffering must be used.IOException
- if the file could not be opened for write.public static XMLWriter createWriter(Writer writer, Map<?,?> options) throws IOException
XMLWriter
instance for the specified writer, using the serialization options.writer
- the writer where to write XML data.options
- the options to control the XML serialization.IOException
- if the file could not be opened for write.public static CoreException createCoreException(SAXException e)
CoreException
based on the specified XML exception.e
- the exception thrown by the XML parser or writer.CoreException
.