javolution.xml.stream |
Provides StAX-like XML readers/writers which do not require object
creation (such as String) and are consequently faster and more time predictable
than standard StAX classes.
The main difference with "javax.xml.stream.*" classes is the use
of CharSequence instead of String . Since
String is a CharSequence (JDK 1.4+), most
existing StAX code requires very little modification to be used with these
new classes.
For more information about the usage of this package please read the
documentation for the {@link javolution.xml.stream.XMLStreamReader} and
{@link javolution.xml.stream.XMLStreamWriter} interfaces.
For more information about StAX (Streaming API for XML) in general see
Wikipedia: StAX
|
Java Source File Name | Type | Comment |
AttributesImpl.java | Class | This class provides the implementation of the
Attributes interface for the StAX parser. |
EntitiesImpl.java | Class | This class holds defined entities while parsing. |
Location.java | Interface | Provides information on the location of an event. |
NamespaceContext.java | Interface | This interface represents the XML namespace context stack while parsing. |
NamespacesImpl.java | Class | This class represents the namespaces stack while parsing. |
XMLInputFactory.java | Class | The class represents the factory for getting
XMLStreamReader intances.
The
XMLInputFactory.newInstance() default implementation automatically
ObjectFactory.recycle recycles any reader which has been
XMLStreamReader.close closed .
Usage example:[code]
// Lets read a CharSequence input.
String xml = "...";
CharSequenceReader in = new CharSequenceReader().setInput(xml);
// Creates a factory of readers coalescing adjacent character data.
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_COALESCING, true);
// Creates a new reader (potentially recycled).
XMLStreamReader reader = factory.createXMLStreamReader(in);
// Parses XML.
for (int e=reader.next(); e != XMLStreamConstants.END_DOCUMENT; e = reader.next()) {
switch (e) { // Event.
...
}
}
reader.close(); // Automatically recycles this writer. |
XMLOutputFactory.java | Class | The class represents the factory for getting
XMLStreamWriter intances.
The
XMLOutputFactory.newInstance() default implementation automatically
ObjectFactory.recycle recycles any writer which has been
XMLStreamWriter.close closed .
Usage example:[code]
// Lets format to an appendable.
TextBuilder xml = new TextBuilder();
AppendableWriter out = new AppendableWriter(xml);
// Creates a factory producing writers using tab indentation.
XMLOutpuFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.INDENTATION, "/t");
// Creates a new writer (potentially recycled).
XMLStreamWriter writer = factory.createXMLStreamReader(out);
// Formats to XML.
writer.writeStartDocument();
writer.writeStartElement(...);
...
writer.close(); // Automatically recycles this writer. |
XMLStreamConstants.java | Interface | This interface declares the constants used in this API. |
XMLStreamException.java | Class | This class represents the base exception for unexpected processing errors. |
XMLStreamReader.java | Interface | This interface is similar to
javax.xml.stream.XMLStreamReader ; but it does not forces
dynamic allocation when parsing (its methods returns
CharArray CharArray instances instead of
String ).
Except for the speed (faster) and its real-time characteristics
the usage/behavior is about the same as its StAX counterpart.
The
CharArray CharArray instances returned by this reader
supports fast primitive conversions as illustrated below:[code]
// Creates a new reader (potentially recycled). |
XMLStreamReaderImpl.java | Class | This class represents a
javolution.lang.Reusable reusable implementation of
XMLStreamWriter .
Except for the types being used (
CharArray CharArray /
CharSequence CharSequence instead of
String ) the
parsing behavior is about the same as for the standard
javax.xml.stream.XMLStreamReader (although several times
faster).
The
CharArray CharArray instances returned by this reader
supports fast primitive conversions as illustrated below:[code]
// Creates reader for an input sream with unknown encoding.
XMLStreamReaderImpl xmlReader = new XMLStreamReaderImpl().setInput(inputStream);
// Parses.
for (int e=xmlReader.next(); e != XMLStreamConstants.END_DOCUMENT; e = xmlReader.next()) {
switch (e) { // Event.
case XMLStreamConstants.START_ELEMENT:
if (xmlReader.getLocalName().equals("Time")) {
// Reads primitive types (int) attributes directly.
int hour = xmlReader.getAttributeValue("hour").toInt();
int minute = xmlReader.getAttributeValue("minute").toInt();
int second = xmlReader.getAttributeValue("second").toInt();
...
}
...
break;
}
}
// Closes reader, it is automatically reset() and can be reused!
xmlReader.close();
[/code]
This reader returns all contiguous character data in a single
chunk (always coalescing). |
XMLStreamWriter.java | Interface | 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. |
XMLStreamWriterImpl.java | Class | |