Interface XMLEventListener

    • Method Detail

      • reset

        void reset()
        Resets this XML event listener. The state will be set to UNINITIALIZED.
      • getState

        XMLEventListenerState getState()
                                throws java.lang.UnsupportedOperationException
        Returns the current state of this outputter.
        Returns:
        the current state, cannot be null.
        Throws:
        java.lang.UnsupportedOperationException - if this is not a stateful XML event listener.
      • setState

        void setState​(XMLEventListenerState newState,
                      java.lang.String[] newElementStack)
               throws java.lang.IllegalArgumentException
        Sets the state of this XML event listener. Normally, it is not necessary to call this method and it should be used with great care.

        Calling this method with UNINITIALIZED as the state is equivalent to calling reset().

        Parameters:
        newState - the new state, not null.
        newElementStack - the new element stack, if newState == START_TAG_OPEN || newState == WITHIN_ELEMENT then it should be non-null and containing no null elements, otherwise it must be null.
        Throws:
        java.lang.IllegalArgumentException - if newState == null || (newState == START_TAG_OPEN && newElementStack == null) || (newState == WITHIN_ELEMENT && newElementStack == null) || (newState != START_TAG_OPEN && newState != WITHIN_ELEMENT && newElementStack != null) || newElementStack[n] == null (where 0 <= n < newElementStack.length).
      • declaration

        void declaration()
                  throws java.lang.IllegalStateException,
                         java.io.IOException
        Notification of an XML declaration. No encoding is explicitly specified.
        Throws:
        java.lang.IllegalStateException - if getState() != BEFORE_XML_DECLARATION.
        java.io.IOException - if an I/O error occurs; this will set the state to ERROR_STATE.
      • dtd

        void dtd​(java.lang.String name,
                 java.lang.String publicID,
                 java.lang.String systemID)
          throws java.lang.IllegalStateException,
                 java.lang.IllegalArgumentException,
                 InvalidXMLException,
                 java.io.IOException
        Notification of a document type declaration.

        An external subset can be specified using either a system identifier (alone), or using both a public identifier and a system identifier. It can never be specified using a public identifier alone.

        For example, for XHTML 1.0 the public identifier is:

        -//W3C//DTD XHTML 1.0 Transitional//EN

        while the system identifier is:

        http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

        The output is typically similar to this:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        or alternatively, if only the system identifier is specified:
        <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        Parameters:
        name - the name of the document type, not null.
        publicID - the public identifier, can be null.
        systemID - the system identifier, can be null, but otherwise it should be a properly formatted URL, see section 4.2.2 External Entities in the XML 1.0 Specification.
        Throws:
        java.lang.IllegalStateException - if getState() != BEFORE_XML_DECLARATION&& getState() != BEFORE_DTD_DECLARATION.
        java.lang.IllegalArgumentException - if name == null || (publicID != null && systemID == null).
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
        InvalidXMLException
      • attribute

        void attribute​(java.lang.String name,
                       java.lang.String value)
                throws java.lang.IllegalStateException,
                       java.lang.IllegalArgumentException,
                       InvalidXMLException,
                       java.io.IOException
        Adds an attribute to the current element. There must currently be an open element.

        The attribute value is surrounded by single quotes.

        Parameters:
        name - the name of the attribute, not null.
        value - the value of the attribute, not null.
        Throws:
        java.lang.IllegalStateException - if getState() != XMLEventListenerStates.START_TAG_OPEN.
        java.lang.IllegalArgumentException - if name == null || value == null.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
        InvalidXMLException
      • endTag

        void endTag()
             throws java.lang.IllegalStateException,
                    java.io.IOException
        Notification of an element end tag.
        Throws:
        java.lang.IllegalStateException - if getState() != START_TAG_OPEN && getState() != WITHIN_ELEMENT
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • pcdata

        void pcdata​(java.lang.String text)
             throws java.lang.IllegalStateException,
                    java.lang.IllegalArgumentException,
                    InvalidXMLException,
                    java.io.IOException
        Notification of a PCDATA section (as a String).
        Parameters:
        text - the PCDATA section contents, not null.
        Throws:
        java.lang.IllegalStateException - if getState() != START_TAG_OPEN && getState() != WITHIN_ELEMENT
        java.lang.IllegalArgumentException - if text == null.
        InvalidXMLException - if the specified text contains an invalid character.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • pcdata

        void pcdata​(char[] ch,
                    int start,
                    int length)
             throws java.lang.IllegalStateException,
                    java.lang.IllegalArgumentException,
                    java.lang.IndexOutOfBoundsException,
                    InvalidXMLException,
                    java.io.IOException
        Notification of a PCDATA section (as a char array).
        Parameters:
        ch - the character array containing the PCDATA section contents, not null.
        start - the start index in the array, must be >= 0 and it must be < ch.length.
        length - the number of characters to read from the array, must be > 0.
        Throws:
        java.lang.IllegalStateException - if getState() != START_TAG_OPEN && getState() != WITHIN_ELEMENT
        java.lang.IllegalArgumentException - if ch == null || start < 0 || start >= ch.length || length < 0.
        java.lang.IndexOutOfBoundsException - if start + length > ch.length.
        InvalidXMLException - if the specified text contains an invalid character.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • cdata

        void cdata​(java.lang.String text)
            throws java.lang.IllegalStateException,
                   java.lang.IllegalArgumentException,
                   InvalidXMLException,
                   java.io.IOException
        Notification of a CDATA section.

        A CDATA section can contain any string, except "]]>". This will, however, not be checked by this method.

        Left angle brackets and ampersands will be output in their literal form; they need not (and cannot) be escaped using "&lt;" and "&amp;".

        If the specified string is empty (i.e. "".equals(text), then nothing will be output.

        If the specified string contains characters that cannot be printed in this encoding, then the result is undefined.

        Parameters:
        text - the contents of the CDATA section, not null.
        Throws:
        java.lang.IllegalStateException - if getState() != START_TAG_OPEN && getState() != WITHIN_ELEMENT
        java.lang.IllegalArgumentException - if text == null.
        InvalidXMLException - if the specified text contains an invalid character.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • whitespace

        void whitespace​(char[] ch,
                        int start,
                        int length)
                 throws java.lang.IllegalStateException,
                        java.lang.IllegalArgumentException,
                        java.lang.IndexOutOfBoundsException,
                        InvalidXMLException,
                        java.io.IOException
        Notification of ignorable whitespace (as a String). Ignorable whitespace can be found anywhere in an XML document, except above the XML declaration.

        This method does not check if the string actually contains whitespace.

        If the state equals XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set to XMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state is XMLEventListenerStates.START_TAG_OPEN then it will be set to XMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.

        Parameters:
        ch - the character array containing the text to be written, not null.
        start - the start index in the array, must be >= 0 and it must be < ch.length.
        length - the number of characters to read from the array, must be > 0.
        Throws:
        java.lang.IllegalStateException - if getState() == ERROR_STATE.
        java.lang.IllegalArgumentException - if ch == null || start < 0 || start >= ch.length || length < 0.
        java.lang.IndexOutOfBoundsException - if start + length > ch.length.
        InvalidXMLException - if the specified text contains an invalid character.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • pi

        void pi​(java.lang.String target,
                java.lang.String instruction)
         throws java.lang.IllegalStateException,
                java.lang.IllegalArgumentException,
                InvalidXMLException,
                java.io.IOException
        Notification of a processing instruction. A target and an optional instruction should be specified.

        A processing instruction can appear above and below the root element, and between elements. It cannot appear inside an element start or end tag, nor inside a comment. Processing instructions cannot be nested.

        If the state equals XMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set to XMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise the state will not be changed.

        Parameters:
        target - an identification of the application at which the instruction is targeted, not null.
        instruction - the instruction, can be null, which is equivalent to an empty string.
        Throws:
        java.lang.IllegalStateException - if getState() == ERROR_STATE.
        java.lang.IllegalArgumentException - if target == null.
        InvalidXMLException - if the specified text contains an invalid character.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.
      • endDocument

        void endDocument()
                  throws java.lang.IllegalStateException,
                         java.io.IOException
        Notification of the end of the document. After calling this method, none of the other notification methods can be called until reset() is called.
        Throws:
        java.lang.IllegalStateException - if getState() == UNINITIALIZED || getState() == DOCUMENT_ENDED.
        java.io.IOException - if an I/O error occurs; this will set the state to XMLEventListenerStates.ERROR_STATE.