package com.liu.test;
import java.io.IOException;
import com.liu.handler.*;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import com.sun.org.apache.xml.internal.resolver.readers.SAXParserHandler;
public class SAXtest {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
//获取一个saxparserfactory的实例
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
SAXParserHandler handler = new SAXParserHandler();
parser.parse("books.xml", handler);
}
}
package com.liu.handler;
import jdk.internal.org.xml.sax.Attributes;
import jdk.internal.org.xml.sax.SAXException;
import jdk.internal.org.xml.sax.helpers.DefaultHandler;
public class SAXParserHandler extends DefaultHandler {
public void startElement(String arg0, String arg1, String arg2,
Attributes arg3) throws SAXException {
// TODO Auto-generated method stub
super.startElement(arg0, arg1, arg2, arg3);
}
public void endElement(String arg0, String arg1, String arg2)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(arg0, arg1, arg2);
}
/**
* 用来标识解析开始
*/
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
System.out.println("SAX解析开始");
}
/**
* 用来标识解析结束
*/
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
super.endDocument();
System.out.println("SAX解析结束");
}
}
应该是这些包吧
import的包错了 删除重新引包