为了账号安全,请及时绑定邮箱和手机立即绑定

SAX解析出错?

代码如下:

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 回答

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

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java眼中的XML---文件读取
  • 参与学习       83200    人
  • 解答问题       431    个

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

进入课程

SAX解析出错?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信