import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.SAXException; import com.SAXA.HA; import com.SAXbook.Book; public class Sax { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub SAXParserFactory spf=SAXParserFactory.newInstance(); try { SAXParser Sax=spf.newSAXParser(); HA s=new HA(); Sax.parse("book.xml", s);(提示这句话出错) System.out.println("共有"+s.getBook().size()+"本书。"); for (Book b : s.getBook()) { System.out.println(b.getId()); System.out.println(b.getName()); System.out.println(b.getAuthor()); System.out.println(b.getYear()); System.out.println(b.getPrice()); System.out.println(b.getLanguage()); System.out.println("----结束----"); } } 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(); } } }
你看一下你的xml中的</name>写错了