Class DOM2SAX


  • public class DOM2SAX
    extends java.lang.Object
    Helper class that produces a SAX stream from a DOM Document.

    Part of the code here copied and adapted from Apache Xalan-J, src/org/apache/xalan/xsltc/trax/DOM2SAX.java

    • Constructor Summary

      Constructors 
      Constructor Description
      DOM2SAX​(org.xml.sax.ContentHandler handler)
      Main constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void endPrefixMapping​(java.lang.String prefix)  
      private static java.lang.String getLocalName​(org.w3c.dom.Node node)
      If the DOM was created using a DOM 1.0 API, the local name may be null.
      private boolean startPrefixMapping​(java.lang.String prefix, java.lang.String uri)
      Begin the scope of namespace prefix.
      void writeDocument​(org.w3c.dom.Document doc, boolean fragment)
      Writes the given document using the given ContentHandler.
      void writeFragment​(org.w3c.dom.Node node)
      Writes the given fragment using the given ContentHandler.
      private void writeNode​(org.w3c.dom.Node node)
      Writes a node using the given writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • contentHandler

        private org.xml.sax.ContentHandler contentHandler
      • lexicalHandler

        private org.xml.sax.ext.LexicalHandler lexicalHandler
      • prefixes

        private java.util.Map prefixes
    • Constructor Detail

      • DOM2SAX

        public DOM2SAX​(org.xml.sax.ContentHandler handler)
        Main constructor
        Parameters:
        handler - the ContentHandler to send SAX events to
    • Method Detail

      • writeDocument

        public void writeDocument​(org.w3c.dom.Document doc,
                                  boolean fragment)
                           throws org.xml.sax.SAXException
        Writes the given document using the given ContentHandler.
        Parameters:
        doc - DOM document
        fragment - if false no startDocument() and endDocument() calls are issued.
        Throws:
        org.xml.sax.SAXException - In case of a problem while writing XML
      • writeFragment

        public void writeFragment​(org.w3c.dom.Node node)
                           throws org.xml.sax.SAXException
        Writes the given fragment using the given ContentHandler.
        Parameters:
        node - DOM node
        Throws:
        org.xml.sax.SAXException - In case of a problem while writing XML
      • startPrefixMapping

        private boolean startPrefixMapping​(java.lang.String prefix,
                                           java.lang.String uri)
                                    throws org.xml.sax.SAXException
        Begin the scope of namespace prefix. Forward the event to the SAX handler only if the prefix is unknown or it is mapped to a different URI.
        Throws:
        org.xml.sax.SAXException
      • endPrefixMapping

        private void endPrefixMapping​(java.lang.String prefix)
                               throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • getLocalName

        private static java.lang.String getLocalName​(org.w3c.dom.Node node)
        If the DOM was created using a DOM 1.0 API, the local name may be null. If so, get the local name from the qualified name before generating the SAX event.
      • writeNode

        private void writeNode​(org.w3c.dom.Node node)
                        throws org.xml.sax.SAXException
        Writes a node using the given writer.
        Parameters:
        node - node to serialize
        Throws:
        org.xml.sax.SAXException - In case of a problem while writing XML