You could (in theory) use the SAXReader.addHandler() mechanism, 
however ... I think it would be better to write your own SAX 
ContentHandler instead:

<source>
try {
  XMLReader parser = XMLReaderFactory.createXMLReader( 
                                       "org.apache.xerces.parsers.SAXParser");
  parser.setContentHandler( new TestContentHandler());
  parser.parse( "test.xml");
} catch ( SAXException e) {
  e.printStackTrace();
}               

class TestContentHandler implements ContentHandler {
    
  private ArrayList values = new ArrayList();
  private ArrayList activeContent = new ArrayList();
  
  public void startElement(String namespaceURI, String localName, 
                        String qName, Attributes atts) throws SAXException {
    
    if ( localName.equals( "test")) {
      StringBuffer buffer = new StringBuffer();
      activeContent.add( buffer);
    }
  }
  
  public void characters(char[] text, int start, int length) throws
SAXException {
    
    if ( content.size() > 0) {
      StringBuffer buffer = (StringBuffer)activeContent.get( content.size()-1);
      buffer.append( text, start, length);
    }
  }
  
  public void endElement(String namespaceURI, String localName, String
localName)
    throws SAXException {  
    if ( localName.equals( "test")) {
      values.add( activeContent.get( activeContent.size()-1);
      activeContent.remove( activeContent.size()-1);
    }
  } 

  // do nothing methods  
  public void setDocumentLocator(Locator locator) {}
  public void startDocument() throws SAXException {}
  public void endDocument() throws SAXException {}
  public void startPrefixMapping(String prefix, String uri) throws
SAXException {}
  public void endPrefixMapping(String prefix) throws SAXException {}
  public void skippedEntity(String name) throws SAXException {}  
  public void ignorableWhitespace(char[] text, int start, int length)
throws SAXException {}
  public void processingInstruction(String target, String data) throws
SAXException {}
}
</source>

Regards,
Edwin


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to