Code example for XMLReader

Methods: parse, setContentHandler, setErrorHandler, setFeature

0
    elementCount = 0;
    buffer = new StringBuffer();
 
    try { 
      xmlReader = saxParser.getXMLReader();
      xmlReader.setContentHandler(this);
      xmlReader.setErrorHandler(this);
      xmlReader.setFeature("http://xml.org/sax/features/validation", false);
      input = new InputSource(new ReaderWrapper(this.reader));
    } catch (SAXNotRecognizedException e) {
      return false; 
    } catch (SAXNotSupportedException e) {
      return false; 
    } catch (SAXException e) {
      return false; 
    } 
    if (logger.isTraceEnabled()) {
      logger.trace("initialize() - exit");
    } 
    return true; 
  } 
 
  public Object getMessage() {
    if (logger.isTraceEnabled()) {
      logger.trace("getMessage() - entry");
    } 
 
    if (!initialize()) { 
      if (logger.isTraceEnabled()) {
        logger.trace("getMessage() - exit - not yet initialized! Returning null.");
      } 
      return null; 
    } 
    String message = null;
    try { 
      xmlReader.parse(input);
    } catch (IOException e) {
      logger.error("getMessage()", e);
    } catch (SAXEndMessageException e) {
      // received an EndMessage, Return the data 
      message = buffer.toString().trim();