慕盖茨7610259
2016-02-20 16:43
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>写错了
Java眼中的XML---文件读取
83199 学习 · 431 问题
相似问题