Package org.dom4j.io
Class STAXEventWriter
- java.lang.Object
-
- org.dom4j.io.STAXEventWriter
-
-
Constructor Summary
Constructors Constructor Description STAXEventWriter()
STAXEventWriter(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Attribute
createAttribute(Attribute attr)
Characters
createCharacters(CDATA cdata)
Constructs a STAXCharacters
event from a DOM4JCDATA
.Characters
createCharacters(Text text)
Constructs a STAXCharacters
event from a DOM4JText
.Comment
createComment(Comment comment)
DTD
createDTD(DocumentType docType)
Constructs a STAXDTD
event from a DOM4JDocumentType
.EndDocument
createEndDocument(Document doc)
Constructs a STAXEndDocument
event from a DOM4JDocument
.EndElement
createEndElement(Element elem)
Constructs a STAXEndElement
event from a DOM4JElement
.Namespace
createNamespace(Namespace ns)
ProcessingInstruction
createProcessingInstruction(ProcessingInstruction pi)
Constructs a STAXProcessingInstruction
event from a DOM4JProcessingInstruction
.QName
createQName(QName qname)
StartDocument
createStartDocument(Document doc)
Constructs a STAXStartDocument
event from a DOM4JDocument
.StartElement
createStartElement(Element elem)
Constructs a STAXStartElement
event from a DOM4JElement
.XMLEventConsumer
getConsumer()
Returns a reference to the underlying event consumer to which events are written.XMLEventFactory
getEventFactory()
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
writeNamespace(Namespace ns)
Writes a DOM4JNamespace
to the stream.void
writeNode(Node n)
Writes a DOM4JNode
to the stream.void
writeProcessingInstruction(ProcessingInstruction pi)
Writes a DOM4JProcessingInstruction
to the stream.void
writeText(Text text)
Writes a DOM4JText
to the stream.
-
-
-
Constructor Detail
-
STAXEventWriter
public STAXEventWriter()
-
STAXEventWriter
public STAXEventWriter(File file) throws XMLStreamException, IOException
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
public STAXEventWriter(Writer writer) throws XMLStreamException
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
public STAXEventWriter(OutputStream stream) throws XMLStreamException
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
public STAXEventWriter(XMLEventConsumer consumer)
Constructs aSTAXEventWriter
that writes events to the provided event stream.- Parameters:
consumer
- The event stream to which events will be written.
-
-
Method Detail
-
getConsumer
public XMLEventConsumer 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
public void setConsumer(XMLEventConsumer consumer)
Sets the underlying event consumer to which events are written.- Parameters:
consumer
- The event consumer to which events should be written.
-
getEventFactory
public XMLEventFactory getEventFactory()
Returns a reference to the event factory used to construct STAX events.- Returns:
- The event factory used to construct STAX events.
-
setEventFactory
public void setEventFactory(XMLEventFactory eventFactory)
Sets the event factory used to construct STAX events.- Parameters:
eventFactory
- The new event factory.
-
writeNode
public void writeNode(Node n) throws XMLStreamException
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
public void writeChildNodes(Branch branch) throws XMLStreamException
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
public void writeElement(Element elem) throws XMLStreamException
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
public StartElement createStartElement(Element elem)
Constructs a STAXStartElement
event from a DOM4JElement
.- Parameters:
elem
- TheElement
from which to construct the event.- Returns:
- The newly constructed
StartElement
event.
-
createEndElement
public EndElement createEndElement(Element elem)
Constructs a STAXEndElement
event from a DOM4JElement
.- Parameters:
elem
- TheElement
from which to construct the event.- Returns:
- The newly constructed
EndElement
event.
-
writeAttribute
public void writeAttribute(Attribute attr) throws XMLStreamException
Writes a DOM4JAttribute
to the stream.- Parameters:
attr
- TheAttribute
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeNamespace
public void writeNamespace(Namespace ns) throws XMLStreamException
Writes a DOM4JNamespace
to the stream.- Parameters:
ns
- TheNamespace
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeText
public void writeText(Text text) throws XMLStreamException
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
public Characters createCharacters(Text text)
Constructs a STAXCharacters
event from a DOM4JText
.- Parameters:
text
- TheText
from which to construct the event.- Returns:
- The constructed
Characters
event.
-
writeCDATA
public void writeCDATA(CDATA cdata) throws XMLStreamException
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
public Characters createCharacters(CDATA cdata)
Constructs a STAXCharacters
event from a DOM4JCDATA
.- Parameters:
cdata
- TheCDATA
from which to construct the event.- Returns:
- The newly constructed
Characters
event.
-
writeComment
public void writeComment(Comment comment) throws XMLStreamException
Writes a DOM4JComment
to the stream.- Parameters:
comment
- TheComment
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeProcessingInstruction
public void writeProcessingInstruction(ProcessingInstruction pi) throws XMLStreamException
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
public ProcessingInstruction createProcessingInstruction(ProcessingInstruction pi)
Constructs a STAXProcessingInstruction
event from a DOM4JProcessingInstruction
.- Parameters:
pi
- TheProcessingInstruction
from which to construct the event.- Returns:
- The constructed
ProcessingInstruction
event.
-
writeEntity
public void writeEntity(Entity entity) throws XMLStreamException
Writes a DOM4JEntity
to the stream.- Parameters:
entity
- TheEntity
to write to the stream.- Throws:
XMLStreamException
- If an error occurs writing to the stream.
-
writeDocumentType
public void writeDocumentType(DocumentType docType) throws XMLStreamException
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
public DTD createDTD(DocumentType docType)
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
public void writeDocument(Document doc) throws XMLStreamException
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
public StartDocument createStartDocument(Document doc)
Constructs a STAXStartDocument
event from a DOM4JDocument
.- Parameters:
doc
- TheDocument
from which to construct the event.- Returns:
- The constructed
StartDocument
event.
-
createEndDocument
public EndDocument createEndDocument(Document doc)
Constructs a STAXEndDocument
event from a DOM4JDocument
.- Parameters:
doc
- TheDocument
from which to construct the event.- Returns:
- The constructed
EndDocument
event.
-
-