Top Description Fields Constructors Methods
org.dom4j.io

public Class STAXEventReader

extends Object
Class Inheritance
Imports
java.io.InputStream, .Reader, java.util.Iterator, javax.xml.namespace.QName, javax.xml.stream.XMLEventReader, .XMLInputFactory, .XMLStreamConstants, .XMLStreamException, javax.xml.stream.events.Attribute, .Characters, .Comment, .EndElement, .EntityReference, .Namespace, .ProcessingInstruction, .StartDocument, .StartElement, .XMLEvent, org.dom4j.CharacterData, .Document, .DocumentFactory, .Element, .Entity, .Node

Reads a DOM4J Document, as well as other Nodes, from a StAX XMLEventReader.
Author
Christian Niles

Field Summary

Modifier and TypeField and Description
private DocumentFactory
factory

Reference to the DocumentFactory used to build DOM4J nodes.

private XMLInputFactory
inputFactory

A StAX input factory, used to construct streams from IO streams.

Constructor Summary

AccessConstructor and Description
public
STAXEventReader()

Constructs a default STAXEventReader instance with a default DocumentFactory.

public
STAXEventReader(DocumentFactory
The DocumentFactory to use when constructing DOM4J nodes, or null if a default should be used.
factory
)

Constructs a STAXEventReader instance that uses the specified DocumentFactoryto construct DOM4J Nodes.

Method Summary

Modifier and TypeMethod and Description
public Attribute

Returns:

The Attribute constructed from the provided Attribute event.
createAttribute
(Element
DOCUMENT ME!
elem
,
Attribute
The Attribute event from which to construct the new DOM4J Attribute.
attr
)

Constructs a new DOM4J Attribute from the provided StAX Attribute event.

public CharacterData

Returns:

The Text or CDATA object constructed from the provided Characters event.
createCharacterData
(Characters
The Characters event from which to construct the new DOM4J Text or CDATA object.
characters
)

Constructs a new DOM4J Text or CDATA object from the provided Characters event.

public Comment

Returns:

The Comment constructed from the provided Comment event.
createComment
(Comment
The Comment event from which to construct the new DOM4J Comment.
comment
)

Constructs a new DOM4J Comment from the provided StAX Comment event.

public Element

Returns:

The Element constructed from the provided StartElement event.
createElement
(StartElement
The StartElement event from which to construct the new DOM4J Element.
startEvent
)

Constructs a new DOM4J Element from the provided StartElement event.

public Entity

Returns:

The Entity constructed from the provided EntityReference event.
createEntity
(EntityReference
The EntityReference event from which to construct the new DOM4J Entity.
entityRef
)

Constructs a new DOM4J Entity from the provided StAX EntityReference event.

public Namespace

Returns:

The Namespace constructed from the provided Namespace event.
createNamespace
(Namespace
The Namespace event from which to construct the new DOM4J Namespace.
ns
)

Constructs a new DOM4J Namespace from the provided StAX Namespace event.

public ProcessingInstruction

Returns:

The ProcessingInstruction constructed from the provided ProcessingInstruction event.
createProcessingInstruction
(ProcessingInstruction
The ProcessingInstruction event from which to construct the new DOM4J ProcessingInstruction.
pi
)

Constructs a new DOM4J ProcessingInstruction from the provided StAX ProcessingInstruction event.

public QName

Returns:

The newly constructed DOM4J QName.
createQName
(QName
The JAXP QName from which to create a DOM4J QName.
qname
)

Constructs a new DOM4J QName from the provided JAXP QName.

public Attribute

Returns:

The Attribute that was read from the stream.
readAttribute
(XMLEventReader
The event stream from which to read the Attribute.
reader
)

Constructs a DOM4J Attribute from the provided event stream.

public CharacterData

Returns:

The Text or CDATA that was read from the stream.
readCharacters
(XMLEventReader
The event stream from which to read the Text or CDATA.
reader
)

Constructs a DOM4J Text or CDATA section from the provided event stream.

public Comment

Returns:

The Comment that was read from the stream.
readComment
(XMLEventReader
The event stream from which to read the Comment.
reader
)

Constructs a DOM4J Comment from the provided event stream.

public Document

Returns:

The Document that was read from the stream.
readDocument
(InputStream
The I/O stream from which the Document will be read.
is
)

Constructs a StAX event stream from the provided I/O stream and reads a DOM4J document from it.

public Document

Returns:

The Document that was read from the stream.
readDocument
(Reader
The character stream from which the Document will be read.
reader
)

Constructs a StAX event stream from the provided I/O character stream and reads a DOM4J document from it.

public Document

Returns:

The Document that was read from the stream.
readDocument
(InputStream
The I/O stream from which the Document will be read.
is
,
String
A system id used to resolve entities.
systemId
)

Constructs a StAX event stream from the provided I/O stream and reads a DOM4J document from it.

public Document

Returns:

The Document that was read from the stream.
readDocument
(Reader
The character stream from which the Document will be read.
reader
,
String
A system id used to resolve entities.
systemId
)

Constructs a StAX event stream from the provided I/O character stream and reads a DOM4J document from it.

public Document

Returns:

The Documentthat was read from the stream.
readDocument
(XMLEventReader
The event stream from which to read the Document.
reader
)

Reads a DOM4J Documentfrom the provided stream.

public Element

Returns:

The Element that was read from the stream.
readElement
(XMLEventReader
The event stream from which to read the Element.
eventReader
)

Reads a DOM4J Element from the provided event stream.

public Entity

Returns:

The org.dom4j.Entitythat was read from the stream.
readEntityReference
(XMLEventReader
The event stream from which to read the EntityReference.
reader
)

Constructs a DOM4J Entity from the provided event stream.

public Namespace

Returns:

The Namespace that was read from the stream.
readNamespace
(XMLEventReader
The event stream from which to read the Namespace.
reader
)

Constructs a DOM4J Namespace from the provided event stream.

public Node

Returns:

A DOM4J Nodeconstructed from the read events.
readNode
(XMLEventReader
The reader from which events will be read.
reader
)

Reads a Nodefrom the event stream.

public ProcessingInstruction

Returns:

The ProcessingInstruction that was read from the stream.
readProcessingInstruction
(XMLEventReader
The event stream from which to read the ProcessingInstruction.
reader
)

Constructs a DOM4J ProcessingInstruction from the provided event stream.

public void
setDocumentFactory(DocumentFactory
The DocumentFactory to use when constructing DOM4J nodes, or null if a default should be used.
documentFactory
)

Sets the DocumentFactory to be used when constructing DOM4J nodes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

factoryback to summary
private DocumentFactory factory

Reference to the DocumentFactory used to build DOM4J nodes.

inputFactoryback to summary
private XMLInputFactory inputFactory

A StAX input factory, used to construct streams from IO streams.

Constructor Detail

STAXEventReaderback to summary
public STAXEventReader()

Constructs a default STAXEventReader instance with a default DocumentFactory.

STAXEventReaderback to summary
public STAXEventReader(DocumentFactory factory)

Constructs a STAXEventReader instance that uses the specified DocumentFactoryto construct DOM4J Nodes.

Parameters
factory:DocumentFactory

The DocumentFactory to use when constructing DOM4J nodes, or null if a default should be used.

Method Detail

createAttributeback to summary
public Attribute createAttribute(Element elem, Attribute attr)

Constructs a new DOM4J Attribute from the provided StAX Attribute event.

Parameters
elem:Element

DOCUMENT ME!

attr:Attribute

The Attribute event from which to construct the new DOM4J Attribute.

Returns:Attribute

The Attribute constructed from the provided Attribute event.

createCharacterDataback to summary
public CharacterData createCharacterData(Characters characters)

Constructs a new DOM4J Text or CDATA object from the provided Characters event.

Parameters
characters:Characters

The Characters event from which to construct the new DOM4J Text or CDATA object.

Returns:CharacterData

The Text or CDATA object constructed from the provided Characters event.

createCommentback to summary
public Comment createComment(Comment comment)

Constructs a new DOM4J Comment from the provided StAX Comment event.

Parameters
comment:Comment

The Comment event from which to construct the new DOM4J Comment.

Returns:Comment

The Comment constructed from the provided Comment event.

createElementback to summary
public Element createElement(StartElement startEvent)

Constructs a new DOM4J Element from the provided StartElement event. All attributes and namespaces will be added to the returned element.

Parameters
startEvent:StartElement

The StartElement event from which to construct the new DOM4J Element.

Returns:Element

The Element constructed from the provided StartElement event.

createEntityback to summary
public Entity createEntity(EntityReference entityRef)

Constructs a new DOM4J Entity from the provided StAX EntityReference event.

Parameters
entityRef:EntityReference

The EntityReference event from which to construct the new DOM4J Entity.

Returns:Entity

The Entity constructed from the provided EntityReference event.

createNamespaceback to summary
public Namespace createNamespace(Namespace ns)

Constructs a new DOM4J Namespace from the provided StAX Namespace event.

Parameters
ns:Namespace

The Namespace event from which to construct the new DOM4J Namespace.

Returns:Namespace

The Namespace constructed from the provided Namespace event.

createProcessingInstructionback to summary
public ProcessingInstruction createProcessingInstruction(ProcessingInstruction pi)

Constructs a new DOM4J ProcessingInstruction from the provided StAX ProcessingInstruction event.

Parameters
pi:ProcessingInstruction

The ProcessingInstruction event from which to construct the new DOM4J ProcessingInstruction.

Returns:ProcessingInstruction

The ProcessingInstruction constructed from the provided ProcessingInstruction event.

createQNameback to summary
public QName createQName(QName qname)

Constructs a new DOM4J QName from the provided JAXP QName.

Parameters
qname:QName

The JAXP QName from which to create a DOM4J QName.

Returns:QName

The newly constructed DOM4J QName.

readAttributeback to summary
public Attribute readAttribute(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J Attribute from the provided event stream. The stream must be positioned before an Attributeevent.

Parameters
reader:XMLEventReader

The event stream from which to read the Attribute.

Returns:Attribute

The Attribute that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before an Attributeevent.
readCharactersback to summary
public CharacterData readCharacters(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J Text or CDATA section from the provided event stream. The stream must be positioned before a Charactersevent.

Parameters
reader:XMLEventReader

The event stream from which to read the Text or CDATA.

Returns:CharacterData

The Text or CDATA that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before a Charactersevent.
readCommentback to summary
public Comment readComment(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J Comment from the provided event stream. The stream must be positioned before a Commentevent.

Parameters
reader:XMLEventReader

The event stream from which to read the Comment.

Returns:Comment

The Comment that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before a Commentevent.
readDocumentback to summary
public Document readDocument(InputStream is) throws XMLStreamException

Constructs a StAX event stream from the provided I/O stream and reads a DOM4J document from it.

Parameters
is:InputStream

The I/O stream from which the Document will be read.

Returns:Document

The Document that was read from the stream.

Exceptions
XMLStreamException:
If an error occurs reading content from the stream.
readDocumentback to summary
public Document readDocument(Reader reader) throws XMLStreamException

Constructs a StAX event stream from the provided I/O character stream and reads a DOM4J document from it.

Parameters
reader:Reader

The character stream from which the Document will be read.

Returns:Document

The Document that was read from the stream.

Exceptions
XMLStreamException:
If an error occurs reading content from the stream.
readDocumentback to summary
public Document readDocument(InputStream is, String systemId) throws XMLStreamException

Constructs a StAX event stream from the provided I/O stream and reads a DOM4J document from it.

Parameters
is:InputStream

The I/O stream from which the Document will be read.

systemId:String

A system id used to resolve entities.

Returns:Document

The Document that was read from the stream.

Exceptions
XMLStreamException:
If an error occurs reading content from the stream.
readDocumentback to summary
public Document readDocument(Reader reader, String systemId) throws XMLStreamException

Constructs a StAX event stream from the provided I/O character stream and reads a DOM4J document from it.

Parameters
reader:Reader

The character stream from which the Document will be read.

systemId:String

A system id used to resolve entities.

Returns:Document

The Document that was read from the stream.

Exceptions
XMLStreamException:
If an error occurs reading content from the stream.
readDocumentback to summary
public Document readDocument(XMLEventReader reader) throws XMLStreamException

Reads a DOM4J Documentfrom the provided stream. The stream should be positioned at the start of a document, or before a StartElement event.

Parameters
reader:XMLEventReader

The event stream from which to read the Document.

Returns:Document

The Documentthat was read from the stream.

Exceptions
XMLStreamException:
If an error occurs reading events from the stream.
readElementback to summary
public Element readElement(XMLEventReader eventReader) throws XMLStreamException

Reads a DOM4J Element from the provided event stream. The stream must be positioned before an StartElementevent. In addition to the initial start event, all events up to and including the closing EndElement will be read, and included with the returned element.

Parameters
eventReader:XMLEventReader

The event stream from which to read the Element.

Returns:Element

The Element that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before a StartElementevent.
readEntityReferenceback to summary
public Entity readEntityReference(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J Entity from the provided event stream. The stream must be positioned before an EntityReferenceevent.

Parameters
reader:XMLEventReader

The event stream from which to read the EntityReference.

Returns:Entity

The org.dom4j.Entitythat was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before an EntityReference event.
readNamespaceback to summary
public Namespace readNamespace(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J Namespace from the provided event stream. The stream must be positioned before a Namespaceevent.

Parameters
reader:XMLEventReader

The event stream from which to read the Namespace.

Returns:Namespace

The Namespace that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before a Namespaceevent.
readNodeback to summary
public Node readNode(XMLEventReader reader) throws XMLStreamException

Reads a Nodefrom the event stream. If the next event is a StartElement, all events until the closing EndElement will be read, and the resulting nodes will be added to the returned Element.

Pre-Conditions : The stream must be positioned before an event other than an EndElement,EndDocument, or any DTD-related events, which are not currently supported.

Parameters
reader:XMLEventReader

The reader from which events will be read.

Returns:Node

A DOM4J Nodeconstructed from the read events.

Exceptions
XMLStreamException:
If an error occurs reading from the stream, or the stream was positioned before an unsupported event.
readProcessingInstructionback to summary
public ProcessingInstruction readProcessingInstruction(XMLEventReader reader) throws XMLStreamException

Constructs a DOM4J ProcessingInstruction from the provided event stream. The stream must be positioned before a ProcessingInstruction event.

Parameters
reader:XMLEventReader

The event stream from which to read the ProcessingInstruction.

Returns:ProcessingInstruction

The ProcessingInstruction that was read from the stream.

Exceptions
XMLStreamException:
If an error occured reading events from the stream, or the stream was not positioned before a ProcessingInstruction event.
setDocumentFactoryback to summary
public void setDocumentFactory(DocumentFactory documentFactory)

Sets the DocumentFactory to be used when constructing DOM4J nodes.

Parameters
documentFactory:DocumentFactory

The DocumentFactory to use when constructing DOM4J nodes, or null if a default should be used.