Class FilteredSaxHandler

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler

    public class FilteredSaxHandler
    extends org.jdom.input.SAXHandler
    A Sax Handler that provides full jdom Elements for specified element names. The elements are detached from their parent elements, which allows parsing of XML files that are too large to fit in memory.

    Typically this class is used with FastSaxBuilder by overriding FastSaxBuilder.createContentHandler().

    • Field Summary

      • Fields inherited from class org.jdom.input.SAXHandler

        inCDATA, previousCDATA, suppress
    • Constructor Summary

      Constructors 
      Constructor Description
      FilteredSaxHandler​(java.util.List<java.lang.String> elementNamesToMatch, FilteredSaxHandler.ElementHandler elementHandler, long maximumExpectedSize)
      Creates a sax handler that provides elements matching a given name pattern to a callback.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(char[] ch, int start, int length)  
      void clearTextBufferCache()  
      void endElement​(java.lang.String namespace, java.lang.String localName, java.lang.String qName)  
      protected void flushCharacters()  
      protected void flushCharactersAtElementEnd()  
      void setIgnoreBoundaryWhitespaceWithSiblings​(boolean ignoringWhiteWithSiblings)
      Similar to SAXHandler.setIgnoringBoundaryWhitespace(boolean) except that we only eliminate text nodes that have siblings.
      void startElement​(java.lang.String namespace, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)  
      • Methods inherited from class org.jdom.input.SAXHandler

        attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, flushCharacters, getCurrentElement, getDocument, getDocumentLocator, getExpandEntities, getFactory, getIgnoringBoundaryWhitespace, getIgnoringElementContentWhitespace, ignorableWhitespace, internalEntityDecl, notationDecl, processingInstruction, pushElement, setDocumentLocator, setExpandEntities, setIgnoringBoundaryWhitespace, setIgnoringElementContentWhitespace, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping, unparsedEntityDecl
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        endDocument, endPrefixMapping, error, fatalError, resolveEntity, warning
      • Methods inherited from class java.lang.Object

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

      • FilteredSaxHandler

        public FilteredSaxHandler​(java.util.List<java.lang.String> elementNamesToMatch,
                                  FilteredSaxHandler.ElementHandler elementHandler,
                                  long maximumExpectedSize)
        Creates a sax handler that provides elements matching a given name pattern to a callback.
        Parameters:
        elementNamesToMatch - the names of elements to report to elementHandler. These are slash (/) separated element names where * represents any element name. e.g. "rootElementName/childElementName" or "rootElementName/*"
        elementHandler - a callback to report all elements matching elementNamesToMatch are reported to. The matching elements will be detached from their parent element, allowing parsing of XML files that are too large to fit in memory.
        maximumExpectedSize - the maximum size in bytes of the data that will be read from the input stream. This is used to allocate more appropriate buffer sizes and hence reduce memory usage and increase speed. This may be <=0 in which case performance and memory usage may not be as good.
    • Method Detail

      • startElement

        public void startElement​(java.lang.String namespace,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.jdom.input.SAXHandler
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String namespace,
                               java.lang.String localName,
                               java.lang.String qName)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.jdom.input.SAXHandler
        Throws:
        org.xml.sax.SAXException
      • setIgnoreBoundaryWhitespaceWithSiblings

        public void setIgnoreBoundaryWhitespaceWithSiblings​(boolean ignoringWhiteWithSiblings)
        Similar to SAXHandler.setIgnoringBoundaryWhitespace(boolean) except that we only eliminate text nodes that have siblings. e.g. <x><y> </y></x> will preserve the space text in y.
        But <x><y> <z></z></y></x> will not preserve the space text in y which is a sibling to "z".
        Parameters:
        ignoringWhiteWithSiblings - Whether to ignore only whitespace content
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.jdom.input.SAXHandler
        Throws:
        org.xml.sax.SAXException
      • flushCharacters

        protected void flushCharacters()
                                throws org.xml.sax.SAXException
        Overrides:
        flushCharacters in class org.jdom.input.SAXHandler
        Throws:
        org.xml.sax.SAXException
      • flushCharactersAtElementEnd

        protected void flushCharactersAtElementEnd()
                                            throws org.xml.sax.SAXException
        Overrides:
        flushCharactersAtElementEnd in class org.jdom.input.SAXHandler
        Throws:
        org.xml.sax.SAXException
      • clearTextBufferCache

        public void clearTextBufferCache()