SAX解析出错?

来源:3-1 使用 SAX 解析 XML 文件的开始和结束

慕仔7135344

2016-12-12 20:16

代码如下:

package com.imooc.test;


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.imooc.handler.SAXParserHandler;


public class SAXTest {


public static void main(String[] args) {

// TODO Auto-generated method stub

SAXParserFactory factory=SAXParserFactory.newInstance();

SAXParser parser;

try {

parser = factory.newSAXParser();

SAXParserHandler hander=new SAXParserHandler();

parser.parse("books.xml", hander);

 

} 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();

}


}


}

错误提示:

SAX解析开始

org.xml.sax.SAXParseException; systemId: file:///D:/%E6%90%9C%E7%8B%97%E9%AB%98%E9%80%9F%E4%B8%8B%E8%BD%BD/eclipse442win32/SAXTest/books.xml; lineNumber: 1; columnNumber: 37; 应该有伪属性名。

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)

at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1465)

at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPseudoAttribute(XMLScanner.java:614)

at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanXMLDeclOrTextDecl(XMLScanner.java:459)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanXMLDeclOrTextDecl(XMLDocumentFragmentScannerImpl.java:947)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XMLDeclDriver.next(XMLDocumentScannerImpl.java:774)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:442)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)

at javax.xml.parsers.SAXParser.parse(SAXParser.java:274)

at com.imooc.test.SAXTest.main(SAXTest.java:25)

求解?

写回答 关注

1回答

  • Deller
    2016-12-13 09:29:05
    已采纳

    看看你的xml文件内容是不是有错误,仔细检查一下,不行的话贴出来看一下

Java眼中的XML---文件读取

通过Java认识并且创造XML文件,如何应用 Java“解析 XML

83202 学习 · 431 问题

查看课程

相似问题

SAX解析

回答 3

SAX解析

回答 1

SAX解析xml

回答 2

SAX解析xml

回答 1

SAX解析xml

回答 2