digester解析xml_org.xml.sax.SAXParseException; lineNumber: 2193; columnNumber: 41; 引用了实体 "nbsp", 但未声明它

前端之家收集整理的这篇文章主要介绍了digester解析xml_org.xml.sax.SAXParseException; lineNumber: 2193; columnNumber: 41; 引用了实体 "nbsp", 但未声明它前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
四月 14,2014 2:00:45 下午 org.apache.commons.digester.Digester fatalError
严重: Parse Fatal Error at line 2193173 column 41: 引用了实体 "nbsp",但未声明它。
org.xml.sax.SAXParseException; lineNumber: 2193173; columnNumber: 41; 引用了实体 "nbsp",但未声明它。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at ParseXML.parse(ParseXML.java:50)
at ParseXML.main(ParseXML.java:69)

org.xml.sax.SAXParseException; lineNumber: 2193173; columnNumber: 41; 引用了实体 "nbsp",但未声明它。
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at ParseXML.parse(ParseXML.java:50)

at ParseXML.main(ParseXML.java:69)

错误原因:xml文档中有" "这个值,解析的时候碰到"&"会认为nbsp是转义字符,而又没有在头部定义转义字符。

解决方法1:在xml文档中将所有"&"替换成"&amp;", 另外"<" = "&lt;" ">" = "&gt;" "'" = "&apos;" """ = "&quot;" 解决方法2:在根元素之前声明实体如下: <!DOCTYPE 根元素标签名 [ <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY yen "¥"> <!ENTITY euro "€"> ]> 在根元素下面的元素中碰到对应的实体会转变成对应的字符,如此处"&nbsp;"变成" "(空格)

原文链接:https://www.f2er.com/xml/298733.html

猜你在找的XML相关文章