|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnux.xom.io.StaxUtil
public class StaxUtil
Various utilities; a XOM Builder implementation that uses a StAX parser instead of a SAX parser; a XMLStreamReader implementation reading from an underlying XOM Document or fragment; plus other tools.
Also see AXIOM StAX introduction.
Method Summary | |
---|---|
static Builder |
createBuilder(XMLInputFactory inputFactory,
NodeFactory factory)
Constructs and returns a Builder implementation that uses a StAX parser instead of a SAX parser. |
static XMLStreamReader |
createXMLStreamReader(InputStream input,
String baseURI)
Constructs and returns a StAX XML pull parser for the given input stream. |
static XMLStreamReader |
createXMLStreamReader(Node root)
Constructs and returns a StAX XMLStreamReader pull parser
implementation that reads from an underlying XOM Node; typically a
Document or fragment (subtree); Ideal for efficient conversion of a
XOM tree to SOAP/AXIOM, JAXB 2, JiBX or XMLBeans,
for example when incrementally converting XQuery results via an
Unmarshaller , perhaps in combination with a
StreamingPathFilter . |
static String |
toString(int eventType)
Returns a debug string representation for the given StAX event type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static XMLStreamReader createXMLStreamReader(Node root)
XMLStreamReader
pull parser
implementation that reads from an underlying XOM Node; typically a
Document or fragment (subtree); Ideal for efficient conversion of a
XOM tree to SOAP/AXIOM, JAXB 2, JiBX or XMLBeans,
for example when incrementally converting XQuery results via an
Unmarshaller
, perhaps in combination with a
StreamingPathFilter
.
The parser is namespace aware, non-validating and text coalescing.
Example usage:
Document doc = new Builder().build("samples/data/articles.xml"); Nodes results = XQueryUtil.xquery(doc, "/articles/article"); Unmarshaller unmarshaller = JAXBContext.newInstance(...).createUnmarshaller(); for (int i=0; i < results.size(); i++) { XMLStreamReader reader = StaxUtil.createXMLStreamReader(results.get(i)); Object jaxbObject = unmarshaller.unmarshall(reader); ... do something with the JAXB object }
root
- the root node of the subtree to read from; typically a
Document or Element; can be parentless.
XMLStreamConstants.START_DOCUMENT and
XMLStreamConstants.END_DOCUMENT events will not be emitted if
the root is an Element, i.e. a fragment. If the root is not a
ParentNode
, the XMLStreamReader's method
hasNext()
will always return false
.
public static Builder createBuilder(XMLInputFactory inputFactory, NodeFactory factory)
inputFactory
- a factory constructing StAX XMLStreamReader
instances.
May be null
in which case a default factory is
used, producing a parser that will be namespace-aware,
DTD-aware, non-validating, and in text-coalescing mode.
In this case the preferred implementation is Woodstox, if available.factory
- the node factory to stream into. May be null
in
which case the default XOM NodeFactory is used, building the
full XML tree.
public static XMLStreamReader createXMLStreamReader(InputStream input, String baseURI) throws ParsingException
The StAX parser will be namespace-aware, DTD-aware, non-validating, and in text-coalescing mode.
input
- the input stream to read from (must not be null)baseURI
- the base URI for the input's document (may be null or empty)
ParsingException
- if there is an error processing the underlying XML sourcepublic static String toString(int eventType)
eventType
- the StAX event type, e.g.
XMLStreamConstants.START_ELEMENT
.
|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |