| javolution.xml.stream.XMLStreamWriter
All known Subclasses: javolution.xml.stream.XMLStreamWriterImpl,
XMLStreamWriter | public interface XMLStreamWriter (Code) | | This interface is similar to
javax.xml.stream.XMLStreamWriter ; but it does not forces
dynamic allocation when formatting (any
CharSequence CharSequence can be used instead of
String ).
Except for the speed (faster) and the added flexibility, the
usage/behavior is about the same as its StAX counterpart.
This writer does not require creating new String objects
during XML formatting. Attributes values can be held by a single/reusable
javolution.text.TextBuilder TextBuilder
(or StringBuilder ) instance to avoid adverse effects
on memory footprint (heap), garbage collection and performance.
For example:[code]
// Creates a new writer (potentially recycled).
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(outputStream);
TextBuilder tmp = new TextBuilder();
writer.writeStartDocument();
...
writer.writeStartElement("Time");
// Writes primitive types (int) attributes (no memory allocation).
writer.writeAttribute("hour", tmp.clear().append(time.hour);
writer.writeAttribute("minute", tmp.clear().append(time.minute);
writer.writeAttribute("second", tmp.clear().append(time.second);
writer.writeEndElement();
...
writer.close(); // Recycles this writer.
outputStream.close(); // Underlying stream has to be closed explicitly.
[/code]
Note: As always, null parameters are not allowed unless
explicitly authorized.
author: Jean-Marie Dautelle version: 4.0, June 16, 2006 |
Method Summary | |
public void | close() Close this writer and free any resources associated with the writer. | public void | flush() Write any cached data to the underlying output mechanism. | public CharSequence | getPrefix(CharSequence uri) Gets the prefix the specified uri is bound to. | public Object | getProperty(String name) Gets the value of a feature/property from the underlying implementation.
Parameters: name - the name of the property. | public void | setDefaultNamespace(CharSequence uri) Binds a URI to the default namespace. | public void | setPrefix(CharSequence prefix, CharSequence uri) Sets the prefix the uri is bound to. | public void | writeAttribute(CharSequence localName, CharSequence value) Writes an attribute to the output stream without a prefix. | public void | writeAttribute(CharSequence prefix, CharSequence namespaceURI, CharSequence localName, CharSequence value) Writes an attribute to the output stream. | public void | writeAttribute(CharSequence namespaceURI, CharSequence localName, CharSequence value) Writes an attribute to the output stream. | public void | writeCData(CharSequence data) Writes a CData section. | public void | writeCharacters(CharSequence text) Writes text to the output. | public void | writeCharacters(char[] text, int start, int length) Writes text to the output. | public void | writeComment(CharSequence data) Writes an xml comment with the data enclosed. | public void | writeDTD(CharSequence dtd) Writes a DTD section (representing the entire doctypedecl
production from the XML 1.0 specification). | public void | writeDefaultNamespace(CharSequence namespaceURI) Writes the default namespace to the stream. | public void | writeEmptyElement(CharSequence namespaceURI, CharSequence localName) Writes an empty element tag to the output. | public void | writeEmptyElement(CharSequence prefix, CharSequence localName, CharSequence namespaceURI) Writes an empty element tag to the output. | public void | writeEmptyElement(CharSequence localName) Writes an empty element tag to the output. | public void | writeEndDocument() Closes any start tags and writes corresponding end tags. | public void | writeEndElement() Writes an end tag to the output relying on the internal state of the
writer to determine the prefix and local name of the event. | public void | writeEntityRef(CharSequence name) | public void | writeNamespace(CharSequence prefix, CharSequence namespaceURI) Writes a namespace to the output stream. | public void | writeProcessingInstruction(CharSequence target) Writes a processing instruction. | public void | writeProcessingInstruction(CharSequence target, CharSequence data) | public void | writeStartDocument() Writes the XML Declaration. | public void | writeStartDocument(CharSequence version) Writes the XML Declaration. | public void | writeStartDocument(CharSequence encoding, CharSequence version) Writes the XML Declaration. | public void | writeStartElement(CharSequence localName) Writes a start tag to the output. | public void | writeStartElement(CharSequence namespaceURI, CharSequence localName) Writes a start tag to the output. | public void | writeStartElement(CharSequence prefix, CharSequence localName, CharSequence namespaceURI) Writes a start tag to the output. |
setDefaultNamespace | public void setDefaultNamespace(CharSequence uri) throws XMLStreamException(Code) | | Binds a URI to the default namespace. This URI is bound in the scope of
the current START_ELEMENT / END_ELEMENT pair. If this method is called
before a START_ELEMENT has been written the uri is bound in the root
scope.
Parameters: uri - the uri to bind to the default namespace or null . throws: XMLStreamException - |
setPrefix | public void setPrefix(CharSequence prefix, CharSequence uri) throws XMLStreamException(Code) | | Sets the prefix the uri is bound to. This prefix is bound in the scope of
the current START_ELEMENT / END_ELEMENT pair. If this method is called
before a START_ELEMENT has been written the prefix is bound in the root
scope.
Parameters: prefix - the prefix to bind to the uri. Parameters: uri - the uri to bind to the prefix or null throws: XMLStreamException - |
writeCharacters | public void writeCharacters(char[] text, int start, int length) throws XMLStreamException(Code) | | Writes text to the output.
Parameters: text - the value to write Parameters: start - the starting position in the array. Parameters: length - the number of characters to write. throws: XMLStreamException - |
writeDefaultNamespace | public void writeDefaultNamespace(CharSequence namespaceURI) throws XMLStreamException(Code) | | Writes the default namespace to the stream.
Parameters: namespaceURI - the uri to bind the default namespace to or null (to map the prefix to "" URI) throws: IllegalStateException - if the current state does not allow namespace writing. throws: XMLStreamException - |
writeEndElement | public void writeEndElement() throws XMLStreamException(Code) | | Writes an end tag to the output relying on the internal state of the
writer to determine the prefix and local name of the event.
throws: XMLStreamException - |
writeNamespace | public void writeNamespace(CharSequence prefix, CharSequence namespaceURI) throws XMLStreamException(Code) | | Writes a namespace to the output stream. If the prefix argument to this
method is the empty string, "xmlns", or null this method
will delegate to writeDefaultNamespace.
Parameters: prefix - the prefix to bind this namespace to or null Parameters: namespaceURI - the uri to bind the prefix. throws: IllegalStateException - if the current state does not allow namespace writing. throws: XMLStreamException - |
writeStartDocument | public void writeStartDocument(CharSequence encoding, CharSequence version) throws XMLStreamException(Code) | | Writes the XML Declaration. Note that the encoding parameter does not set
the actual encoding of the underlying output. That must be set when the
instance when the instance is created using
XMLOutputFactory .
Parameters: encoding - the encoding of the xml declaration or null . Parameters: version - the version of the xml document or null . throws: XMLStreamException - |
writeStartElement | public void writeStartElement(CharSequence localName) throws XMLStreamException(Code) | | Writes a start tag to the output. All writeStartElement methods open a
new scope in the internal namespace context. Writing the corresponding
EndElement causes the scope to be closed.
Parameters: localName - local name of the tag. throws: XMLStreamException - |
|
|