Class DOMConverter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classWe can do simple reuse of commonly seen names -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DocumentBuilderprotected booleanWhether ignorable white space should be ignored, ie not added in the resulting JDOM tree. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String_buildDTD(DocumentType doctype) private static final DocumentBuilderprotected static booleanprotected void_writeElement(org.codehaus.stax2.XMLStreamWriter2 sw, Element elem) Method called to output an element node and all of its children (recursively).protected void_writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, Node node) This method will create aDocumentinstance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader.buildDocument(XMLStreamReader r, DocumentBuilder docbuilder) This method will create aDocumentinstance using given DocumentBuilder and populated using the given StAX stream reader.voidbuildDocument(XMLStreamReader r, Document doc) This method will populate givenDocumentusing the given StAX stream reader instance.voidsetIgnoreWhitespace(boolean state) Method used to change whether the build methods will add ignorable (element) white space in the DOM tree or not.voidwriteDocument(Document doc, XMLStreamWriter sw0) Method for writing out given DOM document using specified stream writer.voidwriteFragment(NodeList nodes, XMLStreamWriter sw0) voidwriteFragment(Node node, XMLStreamWriter sw0)
-
Field Details
-
_docBuilder
-
_inputCfgIgnoreWs
protected boolean _inputCfgIgnoreWsWhether 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.
-
-
Constructor Details
-
DOMConverter
public DOMConverter() -
DOMConverter
-
-
Method Details
-
_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
This method will create aDocumentinstance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader. Namespace-awareness will be enabled for theDocumentBuilderFactoryconstructed; 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:
XMLStreamException- If the reader threw such exception (to indicate a parsing or I/O problem)
-
buildDocument
public Document buildDocument(XMLStreamReader r, DocumentBuilder docbuilder) throws XMLStreamException This method will create aDocumentinstance 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:
XMLStreamException- If the reader threw such exception (to indicate a parsing or I/O problem)
-
buildDocument
This method will populate givenDocumentusing the given StAX stream reader instance.This method takes a
XMLStreamReaderand 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-Documentbeing built.- Throws:
XMLStreamException- If the reader threw such exception (to indicate a parsing or I/O problem)
-
writeDocument
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:
XMLStreamException
-
writeFragment
- Throws:
XMLStreamException
-
writeFragment
- Throws:
XMLStreamException
-
_isNamespaceAware
- Throws:
XMLStreamException
-
_writeNode
protected void _writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, Node node) throws XMLStreamException - Throws:
XMLStreamException
-
_buildDTD
-
_writeElement
protected void _writeElement(org.codehaus.stax2.XMLStreamWriter2 sw, Element elem) throws XMLStreamException Method called to output an element node and all of its children (recursively).- Parameters:
elem- Element to output- Throws:
XMLStreamException
-