package xml;
import java.io.IOException;
import java.util.logging.Handler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import defaulthandler.SAXParserHandler;
public class SaxTest {
public static void main(String[] args) {
SAXParserFactory factory=SAXParserFactory.newInstance();
try {
SAXParser parse=factory.newSAXParser();
SAXParserHandler handler=new SAXParserHandler();
parse.parse("src/res/books.xml", handler);
System.out.println("共存储了"+handler.getSaxBooks().size()+"本书");
for (Books book : handler.getSaxBooks()) {
System.out.println("id: "+book.getId());
System.out.println("name: "+book.getName());
System.out.println("author: "+book.getAuthor());
System.out.println("language: "+book.getLanguage());
System.out.println("price: "+book.getPrice());
System.out.println("year: "+book.getYear());
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
你应该把
SAXParserHandler
的源码发出来
不是getBooklist()吗?
没在一个包下吧,那个方法是default不是public