public class EnhancedXMLStreamWriter extends Object implements XMLStreamWriter
A version of XMLStreamWriter
that adds convenience methods
for adding simple elements and typed attributes, as well as offering
pretty-printing. Can be used on its own with a Writer,
or as a wrapper to an existing XMLStreamWriter
instance.
Constructor and Description |
---|
EnhancedXMLStreamWriter(Writer out) |
EnhancedXMLStreamWriter(Writer out,
boolean writeBlanks)
Creates a new xml stream writer.
|
EnhancedXMLStreamWriter(Writer out,
boolean writeBlanks,
int indent)
Creates a new xml stream writer.
|
EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter) |
EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter,
boolean writeBlanks) |
EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter,
boolean writeBlanks,
int indent)
Creates a new xml stream writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
NamespaceContext |
getNamespaceContext() |
String |
getPrefix(String uri) |
Object |
getProperty(String name) |
void |
setDefaultNamespace(String uri) |
void |
setNamespaceContext(NamespaceContext context) |
void |
setPrefix(String prefix,
String uri) |
void |
writeAttribute(String localName,
String value) |
void |
writeAttribute(String namespaceURI,
String localName,
String value) |
void |
writeAttribute(String prefix,
String namespaceURI,
String localName,
String value) |
void |
writeAttributeBoolean(String localName,
Boolean value) |
void |
writeAttributeBoolean(String localName,
Boolean value,
boolean writeBlanks)
Writes a Boolean attribute.
|
void |
writeAttributeClass(String localName,
Class<?> value) |
void |
writeAttributeClass(String localName,
Class<?> value,
boolean writeBlanks)
Writes an attribute containing a class name, getting it by invoking
Class.getCanonicalName() . |
void |
writeAttributeDouble(String localName,
Double value) |
void |
writeAttributeDouble(String localName,
Double value,
boolean writeBlanks)
Writes a Double attribute.
|
void |
writeAttributeFloat(String localName,
Float value) |
void |
writeAttributeFloat(String localName,
Float value,
boolean writeBlanks)
Writes a Float attribute.
|
void |
writeAttributeInteger(String localName,
Integer value) |
void |
writeAttributeInteger(String localName,
Integer value,
boolean writeBlanks)
Writes a Integer attribute.
|
void |
writeAttributeLong(String localName,
Long value) |
void |
writeAttributeLong(String localName,
Long value,
boolean writeBlanks)
Writes a Long attribute.
|
void |
writeAttributeObject(String localName,
Object value)
Writes an attribute object by first converting it to string
using its "toString()" method.
|
void |
writeAttributeObject(String localName,
Object value,
boolean writeBlanks)
Writes an attribute object by first converting it to string
using its "toString()" method.
|
void |
writeAttributeString(String localName,
String value) |
void |
writeAttributeString(String localName,
String value,
boolean writeBlanks)
Writes a String attribute.
|
void |
writeCData(String data) |
void |
writeCharacters(char[] text,
int start,
int len) |
void |
writeCharacters(String text) |
void |
writeComment(String data) |
void |
writeDefaultNamespace(String namespaceURI) |
void |
writeDTD(String dtd) |
void |
writeElementBoolean(String localName,
Boolean value) |
void |
writeElementBoolean(String localName,
Boolean value,
boolean writeBlanks)
Writes a simple Boolean element.
|
void |
writeElementClass(String localName,
Class<?> value) |
void |
writeElementClass(String localName,
Class<?> value,
boolean writeBlanks)
Writes a simple element containing a class name, getting it by invoking
Class.getCanonicalName() . |
void |
writeElementDimension(String localName,
Dimension value)
Writes a simple element containing a Dimension.
|
void |
writeElementDimension(String localName,
Dimension value,
boolean writeBlanks)
Writes a simple element containing a Dimension.
|
void |
writeElementDouble(String localName,
Double value) |
void |
writeElementDouble(String localName,
Double value,
boolean writeBlanks)
Writes a simple Double element.
|
void |
writeElementFloat(String localName,
Float value) |
void |
writeElementFloat(String localName,
Float value,
boolean writeBlanks)
Writes a simple Float element.
|
void |
writeElementInteger(String localName,
Integer value) |
void |
writeElementInteger(String localName,
Integer value,
boolean writeBlanks)
Writes a simple Integer element.
|
void |
writeElementLong(String localName,
Long value) |
void |
writeElementLong(String localName,
Long value,
boolean writeBlanks)
Writes a simple Long element.
|
void |
writeElementObject(String localName,
Object value)
Writes a simple element object by first converting it to string
using its "toString()" method.
|
void |
writeElementObject(String localName,
Object value,
boolean writeBlanks)
Writes a simple element object by first converting it to string
using its "toString()" method.
|
void |
writeElementString(String localName,
String value) |
void |
writeElementString(String localName,
String value,
boolean writeBlanks)
Writes a simple string element.
|
void |
writeEmptyElement(String localName) |
void |
writeEmptyElement(String namespaceURI,
String localName) |
void |
writeEmptyElement(String prefix,
String localName,
String namespaceURI) |
void |
writeEndDocument() |
void |
writeEndElement() |
void |
writeEntityRef(String name) |
void |
writeNamespace(String prefix,
String namespaceURI) |
void |
writeProcessingInstruction(String target) |
void |
writeProcessingInstruction(String target,
String data) |
void |
writeStartDocument() |
void |
writeStartDocument(String version) |
void |
writeStartDocument(String encoding,
String version) |
void |
writeStartElement(String localName) |
void |
writeStartElement(String namespaceURI,
String localName) |
void |
writeStartElement(String prefix,
String localName,
String namespaceURI) |
public EnhancedXMLStreamWriter(Writer out) throws XMLStreamException
XMLStreamException
public EnhancedXMLStreamWriter(Writer out, boolean writeBlanks) throws XMLStreamException
out
- writer used to write XMLwriteBlanks
- true
to write attributes/elements
with no values when invoking methods without the
"writeBlanks" argument. This sets the default behavior which
can be overwritten using methods with "writeBlanks" argument.XMLStreamException
- problem creating XML stream writerpublic EnhancedXMLStreamWriter(Writer out, boolean writeBlanks, int indent) throws XMLStreamException
out
- writer used to write XMLwriteBlanks
- true
to write attributes/elements
with no values when invoking methods without the
"writeBlanks" argument. This sets the default behavior which
can be overwritten using methods with "writeBlanks" argument.indent
- how many spaces to use for indentation (-1=no indent;
0=newline only; 1+=number of spaces after newline)XMLStreamException
- problem creating XML stream writerpublic EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter)
public EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter, boolean writeBlanks)
public EnhancedXMLStreamWriter(XMLStreamWriter xmlStreamWriter, boolean writeBlanks, int indent)
xmlStreamWriter
- wrapped stream writerwriteBlanks
- true
to write attributes/elements
with no valuesindent
- how many spaces to use for indentation (-1=no indent;
0=newline only; 1+=number of spaces after newline)public void writeAttributeInteger(String localName, Integer value) throws XMLStreamException
XMLStreamException
public void writeAttributeInteger(String localName, Integer value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- Integer attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeLong(String localName, Long value) throws XMLStreamException
XMLStreamException
public void writeAttributeLong(String localName, Long value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- Long attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeFloat(String localName, Float value) throws XMLStreamException
XMLStreamException
public void writeAttributeFloat(String localName, Float value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- Float attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeDouble(String localName, Double value) throws XMLStreamException
XMLStreamException
public void writeAttributeDouble(String localName, Double value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- Double attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeBoolean(String localName, Boolean value) throws XMLStreamException
XMLStreamException
public void writeAttributeBoolean(String localName, Boolean value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- Boolean attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeString(String localName, String value) throws XMLStreamException
XMLStreamException
public void writeAttributeString(String localName, String value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- String attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeClass(String localName, Class<?> value) throws XMLStreamException
XMLStreamException
public void writeAttributeClass(String localName, Class<?> value, boolean writeBlanks) throws XMLStreamException
Class.getCanonicalName()
.localName
- attribute namevalue
- Class attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeAttributeObject(String localName, Object value) throws XMLStreamException
localName
- attribute namevalue
- attribute valueXMLStreamException
- problem writing attributepublic void writeAttributeObject(String localName, Object value, boolean writeBlanks) throws XMLStreamException
localName
- attribute namevalue
- attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.XMLStreamException
- problem writing attributepublic void writeElementInteger(String localName, Integer value) throws XMLStreamException
XMLStreamException
public void writeElementInteger(String localName, Integer value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the Integer valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementLong(String localName, Long value) throws XMLStreamException
XMLStreamException
public void writeElementLong(String localName, Long value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the Long valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementFloat(String localName, Float value) throws XMLStreamException
XMLStreamException
public void writeElementFloat(String localName, Float value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the Float valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementDouble(String localName, Double value) throws XMLStreamException
XMLStreamException
public void writeElementDouble(String localName, Double value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the Double valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementBoolean(String localName, Boolean value) throws XMLStreamException
XMLStreamException
public void writeElementBoolean(String localName, Boolean value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the Boolean valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementString(String localName, String value) throws XMLStreamException
XMLStreamException
public void writeElementString(String localName, String value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the string valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementClass(String localName, Class<?> value) throws XMLStreamException
XMLStreamException
public void writeElementClass(String localName, Class<?> value, boolean writeBlanks) throws XMLStreamException
Class.getCanonicalName()
.localName
- element (tag) namevalue
- the classwriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementDimension(String localName, Dimension value) throws XMLStreamException
localName
- element (tag) namevalue
- the dimensionXMLStreamException
- problem writing elementpublic void writeElementDimension(String localName, Dimension value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- the dimensionwriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeElementObject(String localName, Object value) throws XMLStreamException
localName
- element (tag) namevalue
- element (tag) valueXMLStreamException
- problem writing elementpublic void writeElementObject(String localName, Object value, boolean writeBlanks) throws XMLStreamException
localName
- element (tag) namevalue
- element (tag) valuewriteBlanks
- whether a blank value should be written as an empty element.XMLStreamException
- problem writing elementpublic void writeStartElement(String localName) throws XMLStreamException
writeStartElement
in interface XMLStreamWriter
XMLStreamException
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException
writeStartElement
in interface XMLStreamWriter
XMLStreamException
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeStartElement
in interface XMLStreamWriter
XMLStreamException
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
writeEmptyElement
in interface XMLStreamWriter
XMLStreamException
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeEmptyElement
in interface XMLStreamWriter
XMLStreamException
public void writeEmptyElement(String localName) throws XMLStreamException
writeEmptyElement
in interface XMLStreamWriter
XMLStreamException
public void writeEndElement() throws XMLStreamException
writeEndElement
in interface XMLStreamWriter
XMLStreamException
public void writeEndDocument() throws XMLStreamException
writeEndDocument
in interface XMLStreamWriter
XMLStreamException
public void close() throws XMLStreamException
close
in interface XMLStreamWriter
XMLStreamException
public void flush() throws XMLStreamException
flush
in interface XMLStreamWriter
XMLStreamException
public void writeAttribute(String localName, String value) throws XMLStreamException
writeAttribute
in interface XMLStreamWriter
XMLStreamException
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute
in interface XMLStreamWriter
XMLStreamException
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute
in interface XMLStreamWriter
XMLStreamException
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
writeNamespace
in interface XMLStreamWriter
XMLStreamException
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException
writeDefaultNamespace
in interface XMLStreamWriter
XMLStreamException
public void writeComment(String data) throws XMLStreamException
writeComment
in interface XMLStreamWriter
XMLStreamException
public void writeProcessingInstruction(String target) throws XMLStreamException
writeProcessingInstruction
in interface XMLStreamWriter
XMLStreamException
public void writeProcessingInstruction(String target, String data) throws XMLStreamException
writeProcessingInstruction
in interface XMLStreamWriter
XMLStreamException
public void writeCData(String data) throws XMLStreamException
writeCData
in interface XMLStreamWriter
XMLStreamException
public void writeDTD(String dtd) throws XMLStreamException
writeDTD
in interface XMLStreamWriter
XMLStreamException
public void writeEntityRef(String name) throws XMLStreamException
writeEntityRef
in interface XMLStreamWriter
XMLStreamException
public void writeStartDocument() throws XMLStreamException
writeStartDocument
in interface XMLStreamWriter
XMLStreamException
public void writeStartDocument(String version) throws XMLStreamException
writeStartDocument
in interface XMLStreamWriter
XMLStreamException
public void writeStartDocument(String encoding, String version) throws XMLStreamException
writeStartDocument
in interface XMLStreamWriter
XMLStreamException
public void writeCharacters(String text) throws XMLStreamException
writeCharacters
in interface XMLStreamWriter
XMLStreamException
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException
writeCharacters
in interface XMLStreamWriter
XMLStreamException
public String getPrefix(String uri) throws XMLStreamException
getPrefix
in interface XMLStreamWriter
XMLStreamException
public void setPrefix(String prefix, String uri) throws XMLStreamException
setPrefix
in interface XMLStreamWriter
XMLStreamException
public void setDefaultNamespace(String uri) throws XMLStreamException
setDefaultNamespace
in interface XMLStreamWriter
XMLStreamException
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException
setNamespaceContext
in interface XMLStreamWriter
XMLStreamException
public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface XMLStreamWriter
public Object getProperty(String name)
getProperty
in interface XMLStreamWriter
Copyright © 2008–2021 Norconex Inc.. All rights reserved.