Package org.beanio.stream.xml
Class XmlWriter
- java.lang.Object
-
- org.beanio.stream.xml.XmlWriter
-
- All Implemented Interfaces:
StatefulWriter,RecordWriter
public class XmlWriter extends java.lang.Object implements RecordWriter, StatefulWriter
AXmlWriteris used to write records to a XML output stream. A document object model (DOM) is used to represent a record. Group elements, as indicated by a user data key (see below), are not closed when a record is written. Whenwrite(null)is called, an open group element is closed. Finally, callingflush()will close all remaining group elements and complete the document.A
XmlWritermakes use of the DOM user data feature to pass additional information to and from the parser. TheIS_GROUP_ELEMENTuser data is aBooleanvalue added to an element to indicate the element is group. And theIS_NAMESPACE_IGNOREDuser data is aBooleanvalue set on elements where the XML namespace should be ignored when writing to the output stream.- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringIS_DEFAULT_NAMESPACEThe DOM user data key to indicate whether the declared namespace should override the default namespace.static java.lang.StringIS_GROUP_ELEMENTThe 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 java.lang.StringIS_NAMESPACE_IGNOREDThe DOM user data key to indicate whether the namespace of a DOM element should be ignored when writing to the output stream.
-
Constructor Summary
Constructors Constructor Description XmlWriter(java.io.Writer writer)Constructs a newXmlWriter.XmlWriter(java.io.Writer writer, XmlParserConfiguration config)Constructs a newXmlWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the output stream.voidflush()Flushes the output stream.voidrestoreState(java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)Restores a Map of previously stored state information.voidupdateState(java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)Updates a Map with the current state of the Writer to allow for restoration at a later time.voidwrite(java.lang.Object record)Writes a record object to this output stream.
-
-
-
Field Detail
-
IS_NAMESPACE_IGNORED
public static final java.lang.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. The value must be of typeBoolean.- See Also:
- Constant Field Values
-
IS_DEFAULT_NAMESPACE
public static final java.lang.String IS_DEFAULT_NAMESPACE
The DOM user data key to indicate whether the declared namespace should override the default namespace. The value must be of typeBoolean.- See Also:
- Constant Field Values
-
IS_GROUP_ELEMENT
public static final java.lang.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. The value must of typejava.lang.Boolean.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlWriter
public XmlWriter(java.io.Writer writer)
Constructs a newXmlWriter.- Parameters:
writer- the output stream to write to
-
XmlWriter
public XmlWriter(java.io.Writer writer, XmlParserConfiguration config)Constructs a newXmlWriter.- Parameters:
writer- the output stream to write toconfig- the XML writer configuration
-
-
Method Detail
-
write
public void write(java.lang.Object record) throws java.io.IOExceptionDescription copied from interface:RecordWriterWrites a record object to this output stream.- Specified by:
writein interfaceRecordWriter- Parameters:
record- the record object to write- Throws:
java.io.IOException- if an I/O error occurs writing the record to the stream
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:RecordWriterFlushes the output stream.- Specified by:
flushin interfaceRecordWriter- Throws:
java.io.IOException- if an I/O error occurs flushing the stream
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:RecordWriterCloses the output stream.- Specified by:
closein interfaceRecordWriter- Throws:
java.io.IOException- if an I/O error occurs closing the stream
-
updateState
public void updateState(java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)Description copied from interface:StatefulWriterUpdates a Map with the current state of the Writer to allow for restoration at a later time.- Specified by:
updateStatein interfaceStatefulWriter- Parameters:
namespace- a String to prefix all state keys withstate- the Map to update with the latest state
-
restoreState
public void restoreState(java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state) throws java.lang.IllegalStateExceptionDescription copied from interface:StatefulWriterRestores a Map of previously stored state information.- Specified by:
restoreStatein interfaceStatefulWriter- Parameters:
namespace- a String to prefix all state keys withstate- the Map containing the state to restore- Throws:
java.lang.IllegalStateException- if the Map is missing any state information
-
-