<?xml version="1.0" encoding="UTF-8"?><bookstor><book id="1"><title>""wewe"</title><price>111</price></book><book id="2"><title>"edds"</title><price>234</price></book></bookstor>package re;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;public class Test { public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory a=DocumentBuilderFactory.newInstance(); DocumentBuilder b=a.newDocumentBuilder(); Document c=b.parse("NewFile.xml"); NodeList d=c.getElementsByTagName("book"); System.out.println(d.getLength()); }}[Fatal Error] NewFile.xml:1:39: 文件提前结束。org.xml.sax.SAXParseException; systemId: file:///C:/Users/Administrator/workspace/333/NewFile.xml; lineNumber: 1; columnNumber: 39; 文件提前结束。 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
添加回答
举报
0/150
提交
取消