public class XmlWriter extends Object implements RecordWriter, StatefulWriter
A XmlWriter makes use of the DOM user data feature to pass additional information to and from the parser. The IS_GROUP_ELEMENT user data is a Boolean value added to an element to indicate the element is group. And the IS_NAMESPACE_IGNORED user data is a Boolean value set on elements where the XML namespace should be ignored when writing to the output stream.
Modifier and Type | Field and Description |
---|---|
static String |
IS_DEFAULT_NAMESPACE
The DOM user data key to indicate whether the declared namespace should
override the default namespace.
|
static String |
IS_GROUP_ELEMENT
The DOM user data key to indicate a DOM element is a group element and should
be left "open" when the record is written to the output stream.
|
static String |
IS_NAMESPACE_IGNORED
The DOM user data key to indicate whether the namespace of a DOM element
should be ignored when writing to the output stream.
|
Constructor and Description |
---|
XmlWriter(Writer writer)
Constructs a new XmlWriter.
|
XmlWriter(Writer writer,
XmlParserConfiguration config)
Constructs a new XmlWriter.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the output stream.
|
void |
flush()
Flushes the output stream.
|
void |
restoreState(String namespace,
Map<String,Object> state)
Restores a Map of previously stored state information.
|
void |
updateState(String namespace,
Map<String,Object> state)
Updates a Map with the current state of the Writer to allow for
restoration at a later time.
|
void |
write(Object record)
Writes a record object to this output stream.
|
public static final String IS_NAMESPACE_IGNORED
Boolean
.public static final String IS_DEFAULT_NAMESPACE
Boolean
.public static final String IS_GROUP_ELEMENT
public XmlWriter(Writer writer)
writer
- the output stream to write topublic XmlWriter(Writer writer, XmlParserConfiguration config)
writer
- the output stream to write toconfig
- the XML writer configurationpublic void write(Object record) throws IOException
RecordWriter
write
in interface RecordWriter
record
- the record object to writeIOException
- if an I/O error occurs writing the record to the streampublic void flush() throws IOException
RecordWriter
flush
in interface RecordWriter
IOException
- if an I/O error occurs flushing the streampublic void close() throws IOException
RecordWriter
close
in interface RecordWriter
IOException
- if an I/O error occurs closing the streampublic void updateState(String namespace, Map<String,Object> state)
StatefulWriter
updateState
in interface StatefulWriter
namespace
- a String to prefix all state keys withstate
- the Map to update with the latest statepublic void restoreState(String namespace, Map<String,Object> state) throws IllegalStateException
StatefulWriter
restoreState
in interface StatefulWriter
namespace
- a String to prefix all state keys withstate
- the Map containing the state to restoreIllegalStateException
- if the Map is missing any state information