package sort;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
public class D {
/**
* 使用SAX解析
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
SAXParser parser = factory.newSAXParser() ;
parser.parse(D.class.getClassLoader().getResourceAsStream("NewFile.xml"),
new DefaultHandler(){
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
System.out.println("characters");
}
@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
System.out.println("endDocument");
}
@Override
public void endElement(String uri, String localName,
String qName) throws SAXException {
// TODO Auto-generated method stub
System.out.println("endElement");
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
System.out.println("startDocument");
}
@Override
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
// TODO Auto-generated method stub
System.out.println("startElement");
}
}) ;
}
}