java.lang.Object
org.panteleyev.commons.xml.XMLStreamWriterWrapper
- All Implemented Interfaces:
AutoCloseable
Convenience wrapper for
XMLStreamWriter instances.
Attribute values are converted to string accoring to the following rules:
| Class | String Value |
|---|---|
String | as is |
LocalDateTime | ISO date time |
Enum | Enum.name() |
LocalDate | LocalDate.toEpochDay() or ISO date depending on options. |
Object | Object.toString() |
-
Method Summary
Modifier and TypeMethodDescriptionWrites a single attribute.attributes(Map<QName, ?> attributes) Writes several attributes.voidclose()Closes the writer.voidWrites XML document.voidWrites XML document with root element.Writes XML element.Writes element with attributes.voidflush()Flushes the writer.static XMLStreamWriterWrappernewInstance(OutputStream out) Creates an instance ofXMLStreamWriterWrapperwith default options.static XMLStreamWriterWrappernewInstance(OutputStream out, Set<SerializationOption> options) Creates an instance ofXMLStreamWriterWrapperwith specified options.Writes element text.textElement(QName name, Object value) Writes XML element with text.textElement(QName name, Map<QName, ?> attributes, Object value) Writes element with attributes and text.
-
Method Details
-
newInstance
Creates an instance ofXMLStreamWriterWrapperwith default options.- Parameters:
out- output stream- Returns:
- instance of
XMLStreamWriterWrapper
-
newInstance
public static XMLStreamWriterWrapper newInstance(OutputStream out, Set<SerializationOption> options) Creates an instance ofXMLStreamWriterWrapperwith specified options.- Parameters:
out- output streamoptions- set of options- Returns:
- instance of
XMLStreamWriterWrapper
-
close
public void close()Closes the writer. SeeXMLStreamWriter.close().- Specified by:
closein interfaceAutoCloseable
-
flush
public void flush()Flushes the writer. SeeXMLStreamWriter.flush(). -
document
Writes XML document.- Parameters:
body- block that generates document XML
-
document
Writes XML document with root element.- Parameters:
name- root element namebody- block that generates document XML
-
element
Writes XML element.- Parameters:
name- element namebody- block that generates element XML: attributes, nodes, etc.- Returns:
- this instance
-
textElement
Writes XML element with text.
<localName>text</localName>- Parameters:
name- element namevalue- value converted to element text- Returns:
- this instance
-
element
Writes element with attributes.- Parameters:
name- element nameattributes- attributes- Returns:
- this instance
-
textElement
Writes element with attributes and text.- Parameters:
name- element local nameattributes- attributesvalue- value converted to element text- Returns:
- this instance
-
attribute
Writes a single attribute.- Parameters:
name- attribute namevalue- attribute value- Returns:
- this instance
-
attributes
Writes several attributes.- Parameters:
attributes- attributes- Returns:
- this instance
-
text
Writes element text.- Parameters:
text- element text- Returns:
- this instance
-