You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Stadelmann Adi <Ad...@bison-group.com> on 2001/12/06 09:58:23 UTC

event of endElement while dom parsing

hi
i try to get events (endElement) while dom parsing for saving memory and
performance.
org.w3c.dom.events sends only events about an insert of a element, not
the end of parsing
could xni be my solution?
a simple (but dirty) solution was with xerces1:

public interface DOMHandler {
  /**
   * Handles the current parsed Element
   * For save the memory, you should returning true after handled a
element.
   * This will remove the element in the document-tree
   *
   * @param element the current element
   * @return true if element handled. It will be removed automaticly
form the DOMStreamParser
   * @exception IEException
   * if an error happen while handle
   */
  public boolean handleElementNode(Element elementNode) throws
IEException;
}

and following subclass of DOMParser

public class DOMStreamParser extends DOMParser {
  private DOMHandler _DOMHandler=null;

  public DOMStreamParser() {
    try{
      setDeferNodeExpansion(false);
    } catch (Exception e) {
      System.out.println("Error while setting freature off:"+e);
    }
  }
  
  /**
   * Sets a new DOMHandler
   */
  public void setDOMHandler(DOMHandler handler) {
    _DOMHandler=handler;
  }
  
  /**
   * Gets the DOMHandler
   */
  public DOMHandler getDOMHandler() {
    return _DOMHandler;
  }

  /**
   * Triggering of endElement and send Event to DOMHandler
   */  
  public void endElement(int elementTypeIndex) throws Exception {
    DOMHandler handler=getDOMHandler();
    //First get current Node, because the super.endElement will change
it
    Element elementNode=getCurrentElementNode();
    
    //call the official endElement
    super.endElement(elementTypeIndex);
    
    //Send notification to DOMHandler
    if (handler!=null && elementNode!=null) {
      boolean removeNode=getDOMHandler().handleElementNode(elementNode);
      if (removeNode) ...
    }
  }
}

cu.
Adrian Stadelmann
Software Development
---------------------------------------------------
BISON Schweiz AG
Eichweid 5
CH-6203 Sempach-Station


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org