Class StAXStreamBuilder
- java.lang.Object
-
- org.jdom2.input.StAXStreamBuilder
-
public class StAXStreamBuilder extends java.lang.Object
Builds a JDOM Document from a StAX-based XMLStreamReader.XMLStreamReaders are pre-configured and as a result JDOM is not able to alter whether the input is validated, or whether the Stream has escaped entities or not. These (and other) characteristics are configurable by setting the correct features and properties on the XMLInputFactory when it is used to create the XMLStreamReader.
Useful configuration to set, or know about is:
- StAX streams seldom differentiate between Text and CDATA content. You
will likely want to configure your StAX factory (XMLInputFactory) with
http://java.sun.com/xml/stream/properties/report-cdata-event
for the default Java StAX implementation, or the equivalent property for your StAX engine. - The remaining XMLInputFactory settings are likely to work fine at their default values.
- StAX is not likely to be your best option if you want a validating parser, at least not with the default (built-in Java implementation in Java6 which does not support it). Consider a SAX parser.
From a JDOM perspective XMLStreamReaders are more efficient than XMLEventReaders. Where possible use an XMLStreamReader.
If you happen to be looking at the source code, pay careful attention to the imports so you know what type of instance is being processed, whether it is a StAX class, or a JDOM class, because there are name conflicts.
- Author:
- Rolf Lear
- StAX streams seldom differentiate between Text and CDATA content. You
will likely want to configure your StAX factory (XMLInputFactory) with
-
-
Constructor Summary
Constructors Constructor Description StAXStreamBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Document
build(javax.xml.stream.XMLStreamReader reader)
This builds a document from the supplied XMLStreamReader.java.util.List<Content>
buildFragments(javax.xml.stream.XMLStreamReader reader, StAXFilter filter)
Read the entire XMLStreamReader and from it build a list of Content that conforms to the rules in the supplied StAXFilter.Content
fragment(javax.xml.stream.XMLStreamReader reader)
Read the current XML Fragment from the XMLStreamReader.JDOMFactory
getFactory()
Returns the currentJDOMFactory
in use.void
setFactory(JDOMFactory factory)
This sets a custom JDOMFactory for the builder.
-
-
-
Method Detail
-
getFactory
public JDOMFactory getFactory()
Returns the currentJDOMFactory
in use.- Returns:
- the factory in use
-
setFactory
public void setFactory(JDOMFactory factory)
This sets a custom JDOMFactory for the builder. Use this to build the tree with your own subclasses of the JDOM classes.- Parameters:
factory
-JDOMFactory
to use
-
build
public Document build(javax.xml.stream.XMLStreamReader reader) throws JDOMException
This builds a document from the supplied XMLStreamReader.The JDOMContent will be built by the current JDOMFactory.
- Parameters:
reader
-XMLStreamReader
to read from- Returns:
Document
resultant Document object- Throws:
JDOMException
- when errors occur in parsing
-
buildFragments
public java.util.List<Content> buildFragments(javax.xml.stream.XMLStreamReader reader, StAXFilter filter) throws JDOMException
Read the entire XMLStreamReader and from it build a list of Content that conforms to the rules in the supplied StAXFilter.- Parameters:
reader
- The XMLStreamReader to parsefilter
- The Filter to use for the Content- Returns:
- a List of Content that were identified by the supplied filter
- Throws:
JDOMException
- if there was a parsing problem.
-
fragment
public Content fragment(javax.xml.stream.XMLStreamReader reader) throws JDOMException
Read the current XML Fragment from the XMLStreamReader. The XMLStreamReader must be at some 'content' state, it cannot be at START_DOCUMENT, for example.- Parameters:
reader
- The XMLStreamReader to read the next fragment from- Returns:
- The JDOM fragment at the current position in the reader
- Throws:
JDOMException
- if there is an issue with the state of the XMLStreamReader or some other issue with the processing.
-
-