Package org.dom4j.io
Class STAXEventWriter
java.lang.Object
org.dom4j.io.STAXEventWriter
Writes DOM4J
Node
s to a StAX event stream. In addition the
createXXX
methods are provided to directly create STAX events
from DOM4J nodes.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate XMLEventConsumer
The event stream to which events are written.private XMLEventFactory
The event factory used to construct events.private XMLOutputFactory
-
Constructor Summary
ConstructorsConstructorDescriptionSTAXEventWriter
(File file) Constructs aSTAXEventWriter
that writes events to the provided file.STAXEventWriter
(OutputStream stream) Constructs aSTAXEventWriter
that writes events to the provided stream.STAXEventWriter
(Writer writer) Constructs aSTAXEventWriter
that writes events to the provided character stream.STAXEventWriter
(XMLEventConsumer consumer) Constructs aSTAXEventWriter
that writes events to the provided event stream. -
Method Summary
Modifier and TypeMethodDescriptioncreateAttribute
(Attribute attr) createCharacters
(CDATA cdata) Constructs a STAXCharacters
event from a DOM4JCDATA
.createCharacters
(Text text) Constructs a STAXCharacters
event from a DOM4JText
.createComment
(Comment comment) createDTD
(DocumentType docType) Constructs a STAXDTD
event from a DOM4JDocumentType
.Constructs a STAXEndDocument
event from a DOM4JDocument
.createEndElement
(Element elem) Constructs a STAXEndElement
event from a DOM4JElement
.private EntityReference
createEntityReference
(Entity entity) Constructs a STAXEntityReference
event from a DOM4JEntity
.Constructs a STAXProcessingInstruction
event from a DOM4JProcessingInstruction
.createQName
(QName qname) Constructs a STAXStartDocument
event from a DOM4JDocument
.createStartElement
(Element elem) Constructs a STAXStartElement
event from a DOM4JElement
.Returns a reference to the underlying event consumer to which events are written.Returns a reference to the event factory used to construct STAX events.void
setConsumer
(XMLEventConsumer consumer) Sets the underlying event consumer to which events are written.void
setEventFactory
(XMLEventFactory eventFactory) Sets the event factory used to construct STAX events.void
writeAttribute
(Attribute attr) Writes a DOM4JAttribute
to the stream.void
writeCDATA
(CDATA cdata) Writes a DOM4JCDATA
to the event stream.void
writeChildNodes
(Branch branch) Writes each child node within the providedBranch
instance.void
writeComment
(Comment comment) Writes a DOM4JComment
to the stream.void
writeDocument
(Document doc) Writes a DOM4JDocument
node, and all its contents, to the stream.void
writeDocumentType
(DocumentType docType) Writes a DOM4JDocumentType
to the stream.void
writeElement
(Element elem) Writes a DOM4JElement
node and its children to the stream.void
writeEntity
(Entity entity) Writes a DOM4JEntity
to the stream.void
Writes a DOM4JNamespace
to the stream.void
Writes a DOM4JNode
to the stream.void
Writes a DOM4JProcessingInstruction
to the stream.void
Writes a DOM4JText
to the stream.
-
Field Details
-
consumer
The event stream to which events are written. -
factory
The event factory used to construct events. -
outputFactory
-
-
Constructor Details
-
STAXEventWriter
public STAXEventWriter() -
STAXEventWriter
Constructs aSTAXEventWriter
that writes events to the provided file.- Parameters:
file
- The file to which events will be written.- Throws:
XMLStreamException
- If an error occurs creating an event writer from the file.IOException
- If an error occurs openin the file for writing.
-
STAXEventWriter
Constructs aSTAXEventWriter
that writes events to the provided character stream.- Parameters:
writer
- The character stream to which events will be written.- Throws:
XMLStreamException
- If an error occurs constructing an event writer from the character stream.
-
STAXEventWriter
Constructs aSTAXEventWriter
that writes events to the provided stream.- Parameters:
stream
- The output stream to which events will be written.- Throws:
XMLStreamException
- If an error occurs constructing an event writer from the stream.
-
STAXEventWriter
Constructs aSTAXEventWriter
that writes events to the provided event stream.- Parameters:
consumer
- The event stream to which events will be written.
-
-
Method Details
-
getConsumer
Returns a reference to the underlying event consumer to which events are written.- Returns:
- The underlying event consumer to which events are written.
-
setConsumer
Sets the underlying event consumer to which events are written.- Parameters:
consumer
- The event consumer to which events should be written.
-
getEventFactory
Returns a reference to the event factory used to construct STAX events.- Returns:
- The event factory used to construct STAX events.
-
setEventFactory
Sets the event factory used to construct STAX events.- Parameters:
eventFactory
- The new event factory.
-
writeNode
Writes a DOM4JNode
to the stream. This method is simply a gateway to the overloaded methods such aswriteElement(Element)
.- Parameters:
n
- The DOM4JNode
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeChildNodes
Writes each child node within the providedBranch
instance. This method simply iterates through theBranch
's nodes and callswriteNode(Node)
.- Parameters:
branch
- The node whose children will be written to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeElement
Writes a DOM4JElement
node and its children to the stream.- Parameters:
elem
- TheElement
node to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createStartElement
Constructs a STAXStartElement
event from a DOM4JElement
.- Parameters:
elem
- TheElement
from which to construct the event.- Returns:
- The newly constructed
StartElement
event.
-
createEndElement
Constructs a STAXEndElement
event from a DOM4JElement
.- Parameters:
elem
- TheElement
from which to construct the event.- Returns:
- The newly constructed
EndElement
event.
-
writeAttribute
Writes a DOM4JAttribute
to the stream.- Parameters:
attr
- TheAttribute
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createAttribute
-
writeNamespace
Writes a DOM4JNamespace
to the stream.- Parameters:
ns
- TheNamespace
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createNamespace
-
writeText
Writes a DOM4JText
to the stream.- Parameters:
text
- TheText
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createCharacters
Constructs a STAXCharacters
event from a DOM4JText
.- Parameters:
text
- TheText
from which to construct the event.- Returns:
- The constructed
Characters
event.
-
writeCDATA
Writes a DOM4JCDATA
to the event stream.- Parameters:
cdata
- TheCDATA
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createCharacters
Constructs a STAXCharacters
event from a DOM4JCDATA
.- Parameters:
cdata
- TheCDATA
from which to construct the event.- Returns:
- The newly constructed
Characters
event.
-
writeComment
Writes a DOM4JComment
to the stream.- Parameters:
comment
- TheComment
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createComment
-
writeProcessingInstruction
Writes a DOM4JProcessingInstruction
to the stream.- Parameters:
pi
- TheProcessingInstruction
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createProcessingInstruction
Constructs a STAXProcessingInstruction
event from a DOM4JProcessingInstruction
.- Parameters:
pi
- TheProcessingInstruction
from which to construct the event.- Returns:
- The constructed
ProcessingInstruction
event.
-
writeEntity
Writes a DOM4JEntity
to the stream.- Parameters:
entity
- TheEntity
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createEntityReference
Constructs a STAXEntityReference
event from a DOM4JEntity
.- Parameters:
entity
- TheEntity
from which to construct the event.- Returns:
- The constructed
EntityReference
event.
-
writeDocumentType
Writes a DOM4JDocumentType
to the stream.- Parameters:
docType
- TheDocumentType
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createDTD
Constructs a STAXDTD
event from a DOM4JDocumentType
.- Parameters:
docType
- TheDocumentType
from which to construct the event.- Returns:
- The constructed
DTD
event. - Throws:
RuntimeException
- DOCUMENT ME!
-
writeDocument
Writes a DOM4JDocument
node, and all its contents, to the stream.- Parameters:
doc
- TheDocument
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
createStartDocument
Constructs a STAXStartDocument
event from a DOM4JDocument
.- Parameters:
doc
- TheDocument
from which to construct the event.- Returns:
- The constructed
StartDocument
event.
-
createEndDocument
Constructs a STAXEndDocument
event from a DOM4JDocument
.- Parameters:
doc
- TheDocument
from which to construct the event.- Returns:
- The constructed
EndDocument
event.
-
createQName
-