Class DOMConverter

java.lang.Object
org.codehaus.staxmate.dom.DOMConverter

public class DOMConverter extends Object
Class that can build DOM trees and fragments using Stax stream readers, and write them out using Stax stream writers.
  • Field Details

    • _docBuilder

      protected final 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.
  • Constructor Details

    • DOMConverter

      public DOMConverter()
    • DOMConverter

      public DOMConverter(DocumentBuilder b)
  • Method Details

    • _constructBuilder

      private static final 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 Document buildDocument(XMLStreamReader r) throws XMLStreamException
      This method will create a Document instance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader. Namespace-awareness will be enabled for the DocumentBuilderFactory 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:
      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 a Document 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:
      XMLStreamException - If the reader threw such exception (to indicate a parsing or I/O problem)
    • buildDocument

      public void buildDocument(XMLStreamReader r, Document doc) throws XMLStreamException
      This method will populate given Document 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:
      XMLStreamException - If the reader threw such exception (to indicate a parsing or I/O problem)
    • writeDocument

      public void writeDocument(Document doc, XMLStreamWriter sw0) throws 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:
      XMLStreamException
    • writeFragment

      public void writeFragment(NodeList nodes, XMLStreamWriter sw0) throws XMLStreamException
      Throws:
      XMLStreamException
    • writeFragment

      public void writeFragment(Node node, XMLStreamWriter sw0) throws XMLStreamException
      Throws:
      XMLStreamException
    • _isNamespaceAware

      protected static boolean _isNamespaceAware(XMLStreamReader r) throws XMLStreamException
      Throws:
      XMLStreamException
    • _writeNode

      protected void _writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, Node node) throws XMLStreamException
      Throws:
      XMLStreamException
    • _buildDTD

      protected String _buildDTD(DocumentType doctype)
    • _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