[Biojava-l] SAX parser

Russell Smithies russell.smithies at xtra.co.nz
Tue Jun 24 16:54:22 EDT 2003


It it just me or is Blast's XML screwed?
I've spent a whole day shagging about but couldn't a SAX parser to identify
anything but each elements localName  :-(
The Attributes always seem to be empty.

What have I missed?

Russell

-------------------------------------------
import java.io.*;

import org.apache.xerces.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

//  A Simple SAX Application
//  Extends org.xml.sax.helpers.DefaultHandler
public class BlastParser extends DefaultHandler{
  // Constructor
  public BlastParser(String xmlFile){
    //  Create a Xerces DOM Parser
    SAXParser parser = new SAXParser();
    //  Set Content Handler
    parser.setContentHandler(this);
    //  Parse the Document
    try{
      parser.parse(xmlFile);
    } catch(SAXException e){
      System.err.println(e);
    } catch(IOException e){
      System.err.println(e);
    }
  }


  //  Start Element Event Handler
  public void startElement(String uri, String local, String qName,
Attributes atts){
    System.out.println(local + "  " + atts.getLocalName(0));
  }


  public static void main(String[] args){
    BlastParser basicSAX = new BlastParser(args[0]);
  }
}
---------------------------------------------------------------------




More information about the Biojava-l mailing list