<?xml version='1.0' encoding='UTF-8'?><SMSMSGRECEIVES><SMSMSGRECEIVE><MSGID>2014062940010629110513337600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT>:- < </MSGCONTENT><RECVTIME>2014-06-29 11:05:14</RECVTIME></SMSMSGRECEIVE><SMSMSGRECEIVE><MSGID>2014062940010629105000767600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT> ?行情波段定,不固定。</MSGCONTENT><RECVTIME>2014-06-29 10:50:02</RECVTIME></SMSMSGRECEIVE></SMSMSGRECEIVES>
come on
org.dom4j.DocumentException: Error on line 1 of document : The content of elements must consist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.
at org.dom4j.io.SAXReader.read(SAXReader.java:350)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception:
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.startOfMarkup(XMLDocumentFragmentScannerImpl.java:2606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2704)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.startOfMarkup(XMLDocumentFragmentScannerImpl.java:2606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2704)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
27 个解决方案
#1
包含"&"运行抛错:
[code=java]
<?xml version='1.0' encoding='UTF-8'?><SMSMSGRECEIVES><SMSMSGRECEIVE><MSGID>2014062940010629110513337600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT>:- & </MSGCONTENT><RECVTIME>2014-06-29 11:05:14</RECVTIME></SMSMSGRECEIVE><SMSMSGRECEIVE><MSGID>2014062940010629105000767600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT> ?行情波段定,不固定。</MSGCONTENT><RECVTIME>2014-06-29 10:50:02</RECVTIME></SMSMSGRECEIVE></SMSMSGRECEIVES>
come on
org.dom4j.DocumentException: Error on line 1 of document : The entity name must immediately follow the '&' in the entity reference. Nested exception: The entity name must immediately follow the '&' in the entity reference.
at org.dom4j.io.SAXReader.read(SAXReader.java:350)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception:
org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1846)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3033)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1846)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3033)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
public class Constants {
public static final String ELEMENT_NAME_SMSMSGRECEIVE = "SMSMSGRECEIVE";
public static final String ELEMENT_NAME_MSGID = "MSGID";
public static final String ELEMENT_NAME_DESTTERMID = "DESTTERMID";
public static final String ELEMENT_NAME_SRCTERMID = "SRCTERMID";
public static final String ELEMENT_NAME_MSGCONTENT = "MSGCONTENT";
public static final String ELEMENT_NAME_RECVTIME = "RECVTIME";
}
#21
让你们领导去找接口的提供者,这明显是你得到的数据不合法引起的
如果行政上无法解决,只好建议你用字符串解析的方式,一个节点一个节点地找并且分析了,比如找到
<SMSMSGRECEIVE>和</SMSMSGRECEIVE>的起始索引,然后得到这中间的字符串内容,再用 CDATA 的格式进行再组装,重新创建一个合法的 xml
包含"&"运行抛错:
[code=java]
<?xml version='1.0' encoding='UTF-8'?><SMSMSGRECEIVES><SMSMSGRECEIVE><MSGID>2014062940010629110513337600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT>:- & </MSGCONTENT><RECVTIME>2014-06-29 11:05:14</RECVTIME></SMSMSGRECEIVE><SMSMSGRECEIVE><MSGID>2014062940010629105000767600</MSGID><DESTTERMID>12345</DESTTERMID><SRCTERMID>13301639266</SRCTERMID><MSGCONTENT> ?行情波段定,不固定。</MSGCONTENT><RECVTIME>2014-06-29 10:50:02</RECVTIME></SMSMSGRECEIVE></SMSMSGRECEIVES>
come on
org.dom4j.DocumentException: Error on line 1 of document : The entity name must immediately follow the '&' in the entity reference. Nested exception: The entity name must immediately follow the '&' in the entity reference.
at org.dom4j.io.SAXReader.read(SAXReader.java:350)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception:
org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1846)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3033)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
Nested exception: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1846)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3033)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:216)
at com.clinet.Test.main(Test.java:41)
public class Constants {
public static final String ELEMENT_NAME_SMSMSGRECEIVE = "SMSMSGRECEIVE";
public static final String ELEMENT_NAME_MSGID = "MSGID";
public static final String ELEMENT_NAME_DESTTERMID = "DESTTERMID";
public static final String ELEMENT_NAME_SRCTERMID = "SRCTERMID";
public static final String ELEMENT_NAME_MSGCONTENT = "MSGCONTENT";
public static final String ELEMENT_NAME_RECVTIME = "RECVTIME";
}
#21
让你们领导去找接口的提供者,这明显是你得到的数据不合法引起的
如果行政上无法解决,只好建议你用字符串解析的方式,一个节点一个节点地找并且分析了,比如找到
<SMSMSGRECEIVE>和</SMSMSGRECEIVE>的起始索引,然后得到这中间的字符串内容,再用 CDATA 的格式进行再组装,重新创建一个合法的 xml