Package org.dom4j.io
Class STAXEventWriter
- java.lang.Object
-
- org.dom4j.io.STAXEventWriter
-
public class STAXEventWriter extends java.lang.Object
Writes DOM4JNode
s to a StAX event stream. In addition thecreateXXX
methods are provided to directly create STAX events from DOM4J nodes.
-
-
Constructor Summary
Constructors Constructor Description STAXEventWriter()
STAXEventWriter(java.io.File file)
Constructs aSTAXEventWriter
that writes events to the provided file.STAXEventWriter(java.io.OutputStream stream)
Constructs aSTAXEventWriter
that writes events to the provided stream.STAXEventWriter(java.io.Writer writer)
Constructs aSTAXEventWriter
that writes events to the provided character stream.STAXEventWriter(javax.xml.stream.util.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 javax.xml.stream.events.Attribute
createAttribute(Attribute attr)
Constructs a STAXAttribute
event from a DOM4JAttribute
.javax.xml.stream.events.Comment
createComment(Comment comment)
Constructs a STAXComment
event from a DOM4JComment
.javax.xml.stream.events.DTD
createDTD(DocumentType docType)
Constructs a STAXDTD
event from a DOM4JDocumentType
.javax.xml.stream.events.EndDocument
createEndDocument(Document doc)
Constructs a STAXEndDocument
event from a DOM4JDocument
.javax.xml.stream.events.EndElement
createEndElement(Element elem)
Constructs a STAXEndElement
event from a DOM4JElement
.javax.xml.stream.events.Characters
createCharacters(CDATA cdata)
Constructs a STAXCharacters
event from a DOM4JCDATA
.javax.xml.stream.events.Characters
createCharacters(Text text)
Constructs a STAXCharacters
event from a DOM4JText
.javax.xml.stream.events.Namespace
createNamespace(Namespace ns)
Constructs a STAXNamespace
event from a DOM4JNamespace
.javax.xml.stream.events.ProcessingInstruction
createProcessingInstruction(ProcessingInstruction pi)
Constructs a STAXProcessingInstruction
event from a DOM4JProcessingInstruction
.javax.xml.namespace.QName
createQName(QName qname)
Constructs a STAXQName
from a DOM4JQName
.javax.xml.stream.events.StartDocument
createStartDocument(Document doc)
Constructs a STAXStartDocument
event from a DOM4JDocument
.javax.xml.stream.events.StartElement
createStartElement(Element elem)
Constructs a STAXStartElement
event from a DOM4JElement
.javax.xml.stream.util.XMLEventConsumer
getConsumer()
Returns a reference to the underlying event consumer to which events are written.javax.xml.stream.XMLEventFactory
getEventFactory()
Returns a reference to the event factory used to construct STAX events.void
setConsumer(javax.xml.stream.util.XMLEventConsumer consumer)
Sets the underlying event consumer to which events are written.void
setEventFactory(javax.xml.stream.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
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
writeChildNodes(Branch branch)
Writes each child node within the providedBranch
instance.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(java.io.File file) throws javax.xml.stream.XMLStreamException, java.io.IOException
Constructs aSTAXEventWriter
that writes events to the provided file.- Parameters:
file
- The file to which events will be written.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs creating an event writer from the file.java.io.IOException
- If an error occurs openin the file for writing.
-
STAXEventWriter
public STAXEventWriter(java.io.Writer writer) throws javax.xml.stream.XMLStreamException
Constructs aSTAXEventWriter
that writes events to the provided character stream.- Parameters:
writer
- The character stream to which events will be written.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs constructing an event writer from the character stream.
-
STAXEventWriter
public STAXEventWriter(java.io.OutputStream stream) throws javax.xml.stream.XMLStreamException
Constructs aSTAXEventWriter
that writes events to the provided stream.- Parameters:
stream
- The output stream to which events will be written.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs constructing an event writer from the stream.
-
STAXEventWriter
public STAXEventWriter(javax.xml.stream.util.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 javax.xml.stream.util.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(javax.xml.stream.util.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 javax.xml.stream.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(javax.xml.stream.XMLEventFactory eventFactory)
Sets the event factory used to construct STAX events.- Parameters:
eventFactory
- The new event factory.
-
writeNode
public void writeNode(Node n) throws javax.xml.stream.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:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
writeChildNodes
public void writeChildNodes(Branch branch) throws javax.xml.stream.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:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
writeElement
public void writeElement(Element elem) throws javax.xml.stream.XMLStreamException
Writes a DOM4JElement
node and its children to the stream.- Parameters:
elem
- TheElement
node to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createStartElement
public javax.xml.stream.events.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 javax.xml.stream.events.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 javax.xml.stream.XMLStreamException
Writes a DOM4JAttribute
to the stream.- Parameters:
attr
- TheAttribute
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createAttribute
public javax.xml.stream.events.Attribute createAttribute(Attribute attr)
Constructs a STAXAttribute
event from a DOM4JAttribute
.- Parameters:
attr
- TheAttribute
from which to construct the event.- Returns:
- The newly constructed
Attribute
event.
-
writeNamespace
public void writeNamespace(Namespace ns) throws javax.xml.stream.XMLStreamException
Writes a DOM4JNamespace
to the stream.- Parameters:
ns
- TheNamespace
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createNamespace
public javax.xml.stream.events.Namespace createNamespace(Namespace ns)
Constructs a STAXNamespace
event from a DOM4JNamespace
.- Parameters:
ns
- TheNamespace
from which to construct the event.- Returns:
- The constructed
Namespace
event.
-
writeText
public void writeText(Text text) throws javax.xml.stream.XMLStreamException
Writes a DOM4JText
to the stream.- Parameters:
text
- TheText
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createCharacters
public javax.xml.stream.events.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 javax.xml.stream.XMLStreamException
Writes a DOM4JCDATA
to the event stream.- Parameters:
cdata
- TheCDATA
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createCharacters
public javax.xml.stream.events.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 javax.xml.stream.XMLStreamException
Writes a DOM4JComment
to the stream.- Parameters:
comment
- TheComment
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createComment
public javax.xml.stream.events.Comment createComment(Comment comment)
Constructs a STAXComment
event from a DOM4JComment
.- Parameters:
comment
- TheComment
from which to construct the event.- Returns:
- The constructed
Comment
event.
-
writeProcessingInstruction
public void writeProcessingInstruction(ProcessingInstruction pi) throws javax.xml.stream.XMLStreamException
Writes a DOM4JProcessingInstruction
to the stream.- Parameters:
pi
- TheProcessingInstruction
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createProcessingInstruction
public javax.xml.stream.events.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 javax.xml.stream.XMLStreamException
Writes a DOM4JEntity
to the stream.- Parameters:
entity
- TheEntity
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
writeDocumentType
public void writeDocumentType(DocumentType docType) throws javax.xml.stream.XMLStreamException
Writes a DOM4JDocumentType
to the stream.- Parameters:
docType
- TheDocumentType
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createDTD
public javax.xml.stream.events.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:
java.lang.RuntimeException
- DOCUMENT ME!
-
writeDocument
public void writeDocument(Document doc) throws javax.xml.stream.XMLStreamException
Writes a DOM4JDocument
node, and all its contents, to the stream.- Parameters:
doc
- TheDocument
to write to the stream.- Throws:
javax.xml.stream.XMLStreamException
- If an error occurs writing to the stream.
-
createStartDocument
public javax.xml.stream.events.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 javax.xml.stream.events.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.
-
-