Class NamespaceAndElementFilter

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

    public class NamespaceAndElementFilter
    extends org.xml.sax.helpers.XMLFilterImpl
    This filter enables extraction of a particular element from an XML.

    The filter will bypass only the main element being parsed (such as the AppHdr or Document), ignoring any other sibling or parent content such as a transmission envelope. Then within the main element being processed, only the content with a recognized namespace is propagated, meaning for example any supplementary data with Any in the schema will not be parsed.

    Regarding the namespace, two different behaviours are supported; bounded or unbounded.

    By default the filter will unbind the propagated elements from its namespace. This is done by filtering out the namespace declaration and optional associated prefix. This is useful and actually required when the filter is used by the message parser. When parsing the Document or AppHdr for an MX, we have to unbind the main message namespace because the generated jaxb model for element types is shared and not bounded to any specific message type. Meaning we don't have duplicated type classes for each message they appear in, instead we have single non-repetitive types with no namespace.

    By constructor parameter, the namespace unbinding can also be switched off to let the elements namespace binding untouched. This is useful when the filter is used in the context of a validation against schema.

    Since:
    9.2.1
    • Constructor Summary

      Constructors 
      Constructor Description
      NamespaceAndElementFilter​(java.lang.String localName)  
      NamespaceAndElementFilter​(java.lang.String localName, boolean unbindNamespace)
      Creates the filter with an option to unbinds or not the namespace from the propagated elements
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void endElement​(java.lang.String namespace, java.lang.String localName, java.lang.String prefix)  
      void startElement​(java.lang.String namespace, java.lang.String localName, java.lang.String prefix, org.xml.sax.Attributes attributes)  
      void startPrefixMapping​(java.lang.String prefix, java.lang.String url)  
      • Methods inherited from class org.xml.sax.helpers.XMLFilterImpl

        characters, endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, parse, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

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

      • NamespaceAndElementFilter

        public NamespaceAndElementFilter​(java.lang.String localName)
        Parameters:
        localName - the XML's element to propagate
      • NamespaceAndElementFilter

        public NamespaceAndElementFilter​(java.lang.String localName,
                                         boolean unbindNamespace)
        Creates the filter with an option to unbinds or not the namespace from the propagated elements
        Parameters:
        localName - the XML's element to propagate
        unbindNamespace - true to filter out the namespace declaration and optional associated prefix
    • Method Detail

      • startElement

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

        public void endElement​(java.lang.String namespace,
                               java.lang.String localName,
                               java.lang.String prefix)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.XMLFilterImpl
        Throws:
        org.xml.sax.SAXException
      • startPrefixMapping

        public void startPrefixMapping​(java.lang.String prefix,
                                       java.lang.String url)
                                throws org.xml.sax.SAXException
        Specified by:
        startPrefixMapping in interface org.xml.sax.ContentHandler
        Overrides:
        startPrefixMapping in class org.xml.sax.helpers.XMLFilterImpl
        Throws:
        org.xml.sax.SAXException