Package org.dom4j.io
Class STAXEventWriter
- java.lang.Object
-
- org.dom4j.io.STAXEventWriter
-
public class STAXEventWriter extends java.lang.ObjectWrites DOM4JNodes to a StAX event stream. In addition thecreateXXXmethods are provided to directly create STAX events from DOM4J nodes.
-
-
Constructor Summary
Constructors Constructor Description STAXEventWriter()STAXEventWriter(java.io.File file)Constructs aSTAXEventWriterthat writes events to the provided file.STAXEventWriter(java.io.OutputStream stream)Constructs aSTAXEventWriterthat writes events to the provided stream.STAXEventWriter(java.io.Writer writer)Constructs aSTAXEventWriterthat writes events to the provided character stream.STAXEventWriter(javax.xml.stream.util.XMLEventConsumer consumer)Constructs aSTAXEventWriterthat writes events to the provided event stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.xml.stream.events.AttributecreateAttribute(Attribute attr)Constructs a STAXAttributeevent from a DOM4JAttribute.javax.xml.stream.events.CommentcreateComment(Comment comment)Constructs a STAXCommentevent from a DOM4JComment.javax.xml.stream.events.DTDcreateDTD(DocumentType docType)Constructs a STAXDTDevent from a DOM4JDocumentType.javax.xml.stream.events.EndDocumentcreateEndDocument(Document doc)Constructs a STAXEndDocumentevent from a DOM4JDocument.javax.xml.stream.events.EndElementcreateEndElement(Element elem)Constructs a STAXEndElementevent from a DOM4JElement.javax.xml.stream.events.CharacterscreateCharacters(CDATA cdata)Constructs a STAXCharactersevent from a DOM4JCDATA.javax.xml.stream.events.CharacterscreateCharacters(Text text)Constructs a STAXCharactersevent from a DOM4JText.javax.xml.stream.events.NamespacecreateNamespace(Namespace ns)Constructs a STAXNamespaceevent from a DOM4JNamespace.javax.xml.stream.events.ProcessingInstructioncreateProcessingInstruction(ProcessingInstruction pi)Constructs a STAXProcessingInstructionevent from a DOM4JProcessingInstruction.javax.xml.namespace.QNamecreateQName(QName qname)Constructs a STAXQNamefrom a DOM4JQName.javax.xml.stream.events.StartDocumentcreateStartDocument(Document doc)Constructs a STAXStartDocumentevent from a DOM4JDocument.javax.xml.stream.events.StartElementcreateStartElement(Element elem)Constructs a STAXStartElementevent from a DOM4JElement.javax.xml.stream.util.XMLEventConsumergetConsumer()Returns a reference to the underlying event consumer to which events are written.javax.xml.stream.XMLEventFactorygetEventFactory()Returns a reference to the event factory used to construct STAX events.voidsetConsumer(javax.xml.stream.util.XMLEventConsumer consumer)Sets the underlying event consumer to which events are written.voidsetEventFactory(javax.xml.stream.XMLEventFactory eventFactory)Sets the event factory used to construct STAX events.voidwriteAttribute(Attribute attr)Writes a DOM4JAttributeto the stream.voidwriteCDATA(CDATA cdata)Writes a DOM4JCDATAto the event stream.voidwriteComment(Comment comment)Writes a DOM4JCommentto the stream.voidwriteDocument(Document doc)Writes a DOM4JDocumentnode, and all its contents, to the stream.voidwriteDocumentType(DocumentType docType)Writes a DOM4JDocumentTypeto the stream.voidwriteElement(Element elem)Writes a DOM4JElementnode and its children to the stream.voidwriteEntity(Entity entity)Writes a DOM4JEntityto the stream.voidwriteChildNodes(Branch branch)Writes each child node within the providedBranchinstance.voidwriteNamespace(Namespace ns)Writes a DOM4JNamespaceto the stream.voidwriteNode(Node n)Writes a DOM4JNodeto the stream.voidwriteProcessingInstruction(ProcessingInstruction pi)Writes a DOM4JProcessingInstructionto the stream.voidwriteText(Text text)Writes a DOM4JTextto the stream.
-
-
-
Constructor Detail
-
STAXEventWriter
public STAXEventWriter()
-
STAXEventWriter
public STAXEventWriter(java.io.File file) throws javax.xml.stream.XMLStreamException, java.io.IOExceptionConstructs aSTAXEventWriterthat 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.XMLStreamExceptionConstructs aSTAXEventWriterthat 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.XMLStreamExceptionConstructs aSTAXEventWriterthat 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 aSTAXEventWriterthat 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 DOM4JNodeto the stream. This method is simply a gateway to the overloaded methods such aswriteElement(Element).- Parameters:
n- The DOM4JNodeto 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 providedBranchinstance. 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 DOM4JElementnode and its children to the stream.- Parameters:
elem- TheElementnode 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 STAXStartElementevent from a DOM4JElement.- Parameters:
elem- TheElementfrom which to construct the event.- Returns:
- The newly constructed
StartElementevent.
-
createEndElement
public javax.xml.stream.events.EndElement createEndElement(Element elem)
Constructs a STAXEndElementevent from a DOM4JElement.- Parameters:
elem- TheElementfrom which to construct the event.- Returns:
- The newly constructed
EndElementevent.
-
writeAttribute
public void writeAttribute(Attribute attr) throws javax.xml.stream.XMLStreamException
Writes a DOM4JAttributeto the stream.- Parameters:
attr- TheAttributeto 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 STAXAttributeevent from a DOM4JAttribute.- Parameters:
attr- TheAttributefrom which to construct the event.- Returns:
- The newly constructed
Attributeevent.
-
writeNamespace
public void writeNamespace(Namespace ns) throws javax.xml.stream.XMLStreamException
Writes a DOM4JNamespaceto the stream.- Parameters:
ns- TheNamespaceto 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 STAXNamespaceevent from a DOM4JNamespace.- Parameters:
ns- TheNamespacefrom which to construct the event.- Returns:
- The constructed
Namespaceevent.
-
writeText
public void writeText(Text text) throws javax.xml.stream.XMLStreamException
Writes a DOM4JTextto the stream.- Parameters:
text- TheTextto 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 STAXCharactersevent from a DOM4JText.- Parameters:
text- TheTextfrom which to construct the event.- Returns:
- The constructed
Charactersevent.
-
writeCDATA
public void writeCDATA(CDATA cdata) throws javax.xml.stream.XMLStreamException
Writes a DOM4JCDATAto the event stream.- Parameters:
cdata- TheCDATAto 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 STAXCharactersevent from a DOM4JCDATA.- Parameters:
cdata- TheCDATAfrom which to construct the event.- Returns:
- The newly constructed
Charactersevent.
-
writeComment
public void writeComment(Comment comment) throws javax.xml.stream.XMLStreamException
Writes a DOM4JCommentto the stream.- Parameters:
comment- TheCommentto 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 STAXCommentevent from a DOM4JComment.- Parameters:
comment- TheCommentfrom which to construct the event.- Returns:
- The constructed
Commentevent.
-
writeProcessingInstruction
public void writeProcessingInstruction(ProcessingInstruction pi) throws javax.xml.stream.XMLStreamException
Writes a DOM4JProcessingInstructionto the stream.- Parameters:
pi- TheProcessingInstructionto 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 STAXProcessingInstructionevent from a DOM4JProcessingInstruction.- Parameters:
pi- TheProcessingInstructionfrom which to construct the event.- Returns:
- The constructed
ProcessingInstructionevent.
-
writeEntity
public void writeEntity(Entity entity) throws javax.xml.stream.XMLStreamException
Writes a DOM4JEntityto the stream.- Parameters:
entity- TheEntityto 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 DOM4JDocumentTypeto the stream.- Parameters:
docType- TheDocumentTypeto 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 STAXDTDevent from a DOM4JDocumentType.- Parameters:
docType- TheDocumentTypefrom which to construct the event.- Returns:
- The constructed
DTDevent. - Throws:
java.lang.RuntimeException- DOCUMENT ME!
-
writeDocument
public void writeDocument(Document doc) throws javax.xml.stream.XMLStreamException
Writes a DOM4JDocumentnode, and all its contents, to the stream.- Parameters:
doc- TheDocumentto 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 STAXStartDocumentevent from a DOM4JDocument.- Parameters:
doc- TheDocumentfrom which to construct the event.- Returns:
- The constructed
StartDocumentevent.
-
createEndDocument
public javax.xml.stream.events.EndDocument createEndDocument(Document doc)
Constructs a STAXEndDocumentevent from a DOM4JDocument.- Parameters:
doc- TheDocumentfrom which to construct the event.- Returns:
- The constructed
EndDocumentevent.
-
-