Contents | Package | Class | Tree | Deprecated | Index | Help | XML for Java
PREV | NEXT | SHOW LISTS | HIDE LISTS |

# Interface com.ibm.xml.parser.ElementHandler

public interface ElementHandler

An interface for receiving control when pre-registered element tag names are recognized by the XML4J parser.

This interface is implemented by filter programs which do not want to deal with the complexities of manipulating an entire XML document hierarchy. Rather, filter programs only want to recieve control when a pre-registered set of tags are recognized by the parser.

For example, a filter program may want to convert all `<email>foo@bar</email>` tags to `<url href="mailto:foo@bar"/>`. In this case, the email tag is registered with the XML4J parser instance, prior to parsing the input stream, by using the `addElementHandler` method. Subsequently, the implemented `handleElement` method will be invoked by the XML4J parser instance when the input stream is read; the implemented `handleElement` method is responsible for manipulating the child objects of the `<email>` element. This logic is implemented in the following code fragment:

     public class EMAILFilter implements ElementHandler {
       public TXElement handleElement(TXElement originalElement) {
           String addr;
           if (0 != (addr = originalElement.getText()).length()) {
               TXElement newElement = new TXElement("URL");
               newElement.setAttribute("HREF", "mailto:"+addr);
               originalElement = newElement;
           }
           return originalElement;
       }

       public static void main(String[] argv) {
           ...
           Parser p = new Parser(fname);
           p.addElementHandler(new EMAILFilter(), "EMAIL");   // Watch for EMAIL tag
           // Note: If the above line is changed to p.addElementHandler(new EMAILFilter());,
           //       EMAILFilter is invoked when EACH end tag is recognized by the parser.
           TXDocument doc = p.readStream(p.getInputStream(fname, null, fname));
           // doc instance now contains updated EMAIL Elements.
           ...
       }

Version:
  1.1
See Also:
  addElementHandler(com.ibm.xml.parser.ElementHandler), addElementHandler(com.ibm.xml.parser.ElementHandler,java.lang.String)

Method Summary
TXElement | handleElement(TXElement element) Interface to be implemented for receiving control when pre-registered element tag names are recognized by the XML4J parser.

Method Detail

### handleElement

    public TXElement handleElement(TXElement element)

  Interface to be implemented for receiving control when pre-registered element tag names are recognized by the XML4J parser. Control is transferred after calling any TagHandlers when the end tag is parsed.
  Parameters:
    `element` - An Element that matches the specified name on a prior call to `parser.addElementHandler`. Note that namespace names may also be included in Element names.
  Returns:
    The modified element, or null if the Element is to be removed from the document.
  See Also:
    Namespace, TXElement

Contents | Package | Class | Tree | Deprecated | Index | Help |
PREV | NEXT | SHOW LISTS | HIDE LISTS |