Class DOMConverter
- java.lang.Object
-
- org.codehaus.staxmate.dom.DOMConverter
-
public class DOMConverter extends java.lang.Object
Class that can build DOM trees and fragments using Stax stream readers, and write them out using Stax stream writers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DOMConverter.QNameRecycler
We can do simple reuse of commonly seen names
-
Field Summary
Fields Modifier and Type Field Description protected javax.xml.parsers.DocumentBuilder
_docBuilder
protected boolean
_inputCfgIgnoreWs
Whether ignorable white space should be ignored, ie not added in the resulting JDOM tree.
-
Constructor Summary
Constructors Constructor Description DOMConverter()
DOMConverter(javax.xml.parsers.DocumentBuilder b)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_buildDTD(org.w3c.dom.DocumentType doctype)
private static javax.xml.parsers.DocumentBuilder
_constructBuilder()
protected static boolean
_isNamespaceAware(javax.xml.stream.XMLStreamReader r)
protected void
_writeElement(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Element elem)
Method called to output an element node and all of its children (recursively).protected void
_writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Node node)
org.w3c.dom.Document
buildDocument(javax.xml.stream.XMLStreamReader r)
This method will create aDocument
instance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader.org.w3c.dom.Document
buildDocument(javax.xml.stream.XMLStreamReader r, javax.xml.parsers.DocumentBuilder docbuilder)
This method will create aDocument
instance using given DocumentBuilder and populated using the given StAX stream reader.void
buildDocument(javax.xml.stream.XMLStreamReader r, org.w3c.dom.Document doc)
This method will populate givenDocument
using the given StAX stream reader instance.void
setIgnoreWhitespace(boolean state)
Method used to change whether the build methods will add ignorable (element) white space in the DOM tree or not.void
writeDocument(org.w3c.dom.Document doc, javax.xml.stream.XMLStreamWriter sw0)
Method for writing out given DOM document using specified stream writer.void
writeFragment(org.w3c.dom.NodeList nodes, javax.xml.stream.XMLStreamWriter sw0)
void
writeFragment(org.w3c.dom.Node node, javax.xml.stream.XMLStreamWriter sw0)
-
-
-
Field Detail
-
_docBuilder
protected final javax.xml.parsers.DocumentBuilder _docBuilder
-
_inputCfgIgnoreWs
protected boolean _inputCfgIgnoreWs
Whether ignorable white space should be ignored, ie not added in the resulting JDOM tree. If true, it will be ignored; if false, it will be added in the tree. Default value if false.
-
-
Method Detail
-
_constructBuilder
private static final javax.xml.parsers.DocumentBuilder _constructBuilder()
-
setIgnoreWhitespace
public void setIgnoreWhitespace(boolean state)
Method used to change whether the build methods will add ignorable (element) white space in the DOM tree or not.Whether all-whitespace text segment is ignorable white space or not is based on DTD read in, as per XML specifications (white space is only significant in mixed content or pure text elements).
-
buildDocument
public org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r) throws javax.xml.stream.XMLStreamException
This method will create aDocument
instance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader. Namespace-awareness will be enabled for theDocumentBuilderFactory
constructed; if this is not wanted, caller should construct DocumentBuilder separately.Note: underlying stream reader will not be closed by calling this method.
- Parameters:
r
- Stream reader from which input is read.- Returns:
Document
- DOM document object.- Throws:
javax.xml.stream.XMLStreamException
- If the reader threw such exception (to indicate a parsing or I/O problem)
-
buildDocument
public org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r, javax.xml.parsers.DocumentBuilder docbuilder) throws javax.xml.stream.XMLStreamException
This method will create aDocument
instance using given DocumentBuilder and populated using the given StAX stream reader.Note: underlying stream reader will not be closed by calling this method.
- Parameters:
r
- Stream reader from which input is read.- Returns:
Document
- DOM document object.- Throws:
javax.xml.stream.XMLStreamException
- If the reader threw such exception (to indicate a parsing or I/O problem)
-
buildDocument
public void buildDocument(javax.xml.stream.XMLStreamReader r, org.w3c.dom.Document doc) throws javax.xml.stream.XMLStreamException
This method will populate givenDocument
using the given StAX stream reader instance.This method takes a
XMLStreamReader
and builds up a DOM tree under given document object.Implementation note: recursion has been eliminated by using nodes' parent/child relationship; this improves performance somewhat (classic recursion-by-iteration-and-explicit stack transformation)
Note: underlying stream reader will not be closed by calling this method.
- Parameters:
r
- Stream reader from which input is read.doc
-Document
being built.- Throws:
javax.xml.stream.XMLStreamException
- If the reader threw such exception (to indicate a parsing or I/O problem)
-
writeDocument
public void writeDocument(org.w3c.dom.Document doc, javax.xml.stream.XMLStreamWriter sw0) throws javax.xml.stream.XMLStreamException
Method for writing out given DOM document using specified stream writer.Note: only regular
XMLStreamWriter.close()
is called on the stream writer. This usually means that the underlying stream is not closed (as per Stax 1.0 specification).- Throws:
javax.xml.stream.XMLStreamException
-
writeFragment
public void writeFragment(org.w3c.dom.NodeList nodes, javax.xml.stream.XMLStreamWriter sw0) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
writeFragment
public void writeFragment(org.w3c.dom.Node node, javax.xml.stream.XMLStreamWriter sw0) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_isNamespaceAware
protected static boolean _isNamespaceAware(javax.xml.stream.XMLStreamReader r) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_writeNode
protected void _writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Node node) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_buildDTD
protected java.lang.String _buildDTD(org.w3c.dom.DocumentType doctype)
-
_writeElement
protected void _writeElement(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Element elem) throws javax.xml.stream.XMLStreamException
Method called to output an element node and all of its children (recursively).- Parameters:
elem
- Element to output- Throws:
javax.xml.stream.XMLStreamException
-
-