There are special characters in the XML, causing an error parsing

Source: Internet
Author: User
Tags cdata
2015-01-29 00:10:22,075 ERROR commonapi.commonapiaction-errorcode:5000,5000-00;description: Program exception. Error on line 1 of Document:an invalid XML character (unicode:0x19) is found in the CDATA section. Nested Exception:an Invalid XML character (unicode:0x19) is found in the CDATA section.
Org.dom4j.DocumentException:Error on line 1 of Document:an invalid XML character (unicode:0x19) is found in the Cdat A section. Nested Exception:an Invalid XML character (unicode:0x19) is found in the CDATA section.
At Org.dom4j.io.SAXReader.read (saxreader.java:482)
At Org.dom4j.DocumentHelper.parseText (documenthelper.java:278)
At Com.hoodong.engine.commonapi.CommonApiAction.getWapDocsSearchJsonInfo (commonapiaction.java:1866)
At Sun.reflect.GeneratedMethodAccessor43.invoke (Unknown Source)
At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:25)
At Java.lang.reflect.Method.invoke (method.java:597)
At Org.apache.struts.actions.DispatchAction.dispatchMethod (dispatchaction.java:274)
At Org.apache.struts.actions.DispatchAction.execute (dispatchaction.java:194)
At Org.apache.struts.action.RequestProcessor.processActionPerform (requestprocessor.java:419)
At Org.apache.struts.action.RequestProcessor.process (requestprocessor.java:224)
At Org.apache.struts.action.ActionServlet.process (actionservlet.java:1194)
At Org.apache.struts.action.ActionServlet.doGet (actionservlet.java:414)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:114)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:91)
At Com.caucho.server.dispatch.ServletFilterChain.doFilter (servletfilterchain.java:103)
At Com.caucho.server.webapp.DispatchFilterChain.doFilter (dispatchfilterchain.java:97)
At Com.caucho.server.dispatch.ServletInvocation.service (servletinvocation.java:265)
At Com.caucho.server.webapp.RequestDispatcherImpl.forward (requestdispatcherimpl.java:293)
At Com.caucho.server.webapp.RequestDispatcherImpl.forward (requestdispatcherimpl.java:111)
At Org.apache.struts.action.RequestProcessor.doForward (requestprocessor.java:1063)
At Org.apache.struts.action.RequestProcessor.processForwardConfig (requestprocessor.java:386)
At Org.apache.struts.action.RequestProcessor.process (requestprocessor.java:229)
At Org.apache.struts.action.ActionServlet.process (actionservlet.java:1194)
At Org.apache.struts.action.ActionServlet.doGet (actionservlet.java:414)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:114)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:91)
At Com.caucho.server.dispatch.ServletFilterChain.doFilter (servletfilterchain.java:103)
At Com.hudong.keel.web.filter.CookieAutoLogonFilter.doFilterLogic (cookieautologonfilter.java:137)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.ProductContextFilter.doFilterLogic (productcontextfilter.java:167)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.HttpSessionFilter.doFilterLogic (httpsessionfilter.java:95)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.filter.CaptchaFilter.doFilterLogic (captchafilter.java:68)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.PerformanceMonitorFilter.doFilterLogic (performancemonitorfilter.java:61)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.common.RecordSession.doFilter (recordsession.java:94)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.common.EncodeServlet.doFilter (encodeservlet.java:41)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.caucho.server.webapp.WebAppFilterChain.doFilter (webappfilterchain.java:187)
At Com.caucho.server.dispatch.ServletInvocation.service (servletinvocation.java:265)
At Com.caucho.server.http.HttpRequest.handleRequest (httprequest.java:273)
At Com.caucho.server.port.TcpConnection.run (tcpconnection.java:682)
At Com.caucho.util.threadpool$item.runtasks (threadpool.java:743)
At Com.caucho.util.threadpool$item.run (threadpool.java:662)
At Java.lang.Thread.run (thread.java:619)
Nested Exception:
Org.xml.sax.SAXParseException:An Invalid XML character (unicode:0x19) is found in the CDATA section.
At Org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException (Unknown Source)
At Org.apache.xerces.util.ErrorHandlerWrapper.fatalError (Unknown Source)
At Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source)
At Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source)
At Org.apache.xerces.impl.XMLScanner.reportFatalError (Unknown Source)
At Org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCDATASection (Unknown Source)
At Org.apache.xerces.impl.xmldocumentfragmentscannerimpl$fragmentcontentdispatcher.dispatch (Unknown Source)
At Org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source)
At Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
At Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
At Org.apache.xerces.parsers.XMLParser.parse (Unknown Source)
At Org.apache.xerces.parsers.AbstractSAXParser.parse (Unknown Source)
At Org.dom4j.io.SAXReader.read (saxreader.java:465)
At Org.dom4j.DocumentHelper.parseText (documenthelper.java:278)
At Com.hoodong.engine.commonapi.CommonApiAction.getWapDocsSearchJsonInfo (commonapiaction.java:1866)
At Sun.reflect.GeneratedMethodAccessor43.invoke (Unknown Source)
At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:25)
At Java.lang.reflect.Method.invoke (method.java:597)
At Org.apache.struts.actions.DispatchAction.dispatchMethod (dispatchaction.java:274)
At Org.apache.struts.actions.DispatchAction.execute (dispatchaction.java:194)
At Org.apache.struts.action.RequestProcessor.processActionPerform (requestprocessor.java:419)
At Org.apache.struts.action.RequestProcessor.process (requestprocessor.java:224)
At Org.apache.struts.action.ActionServlet.process (actionservlet.java:1194)
At Org.apache.struts.action.ActionServlet.doGet (actionservlet.java:414)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:114)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:91)
At Com.caucho.server.dispatch.ServletFilterChain.doFilter (servletfilterchain.java:103)
At Com.caucho.server.webapp.DispatchFilterChain.doFilter (dispatchfilterchain.java:97)
At Com.caucho.server.dispatch.ServletInvocation.service (servletinvocation.java:265)
At Com.caucho.server.webapp.RequestDispatcherImpl.forward (requestdispatcherimpl.java:293)
At Com.caucho.server.webapp.RequestDispatcherImpl.forward (requestdispatcherimpl.java:111)
At Org.apache.struts.action.RequestProcessor.doForward (requestprocessor.java:1063)
At Org.apache.struts.action.RequestProcessor.processForwardConfig (requestprocessor.java:386)
At Org.apache.struts.action.RequestProcessor.process (requestprocessor.java:229)
At Org.apache.struts.action.ActionServlet.process (actionservlet.java:1194)
At Org.apache.struts.action.ActionServlet.doGet (actionservlet.java:414)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:114)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:91)
At Com.caucho.server.dispatch.ServletFilterChain.doFilter (servletfilterchain.java:103)
At Com.hudong.keel.web.filter.CookieAutoLogonFilter.doFilterLogic (cookieautologonfilter.java:137)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.ProductContextFilter.doFilterLogic (productcontextfilter.java:167)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.HttpSessionFilter.doFilterLogic (httpsessionfilter.java:95)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.filter.CaptchaFilter.doFilterLogic (captchafilter.java:68)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hudong.keel.web.filter.PerformanceMonitorFilter.doFilterLogic (performancemonitorfilter.java:61)
At Com.hudong.keel.web.filter.AbstractFilter.doFilter (abstractfilter.java:111)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.common.RecordSession.doFilter (recordsession.java:94)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.hoodong.engine.common.EncodeServlet.doFilter (encodeservlet.java:41)
At Com.caucho.server.dispatch.FilterFilterChain.doFilter (filterfilterchain.java:87)
At Com.caucho.server.webapp.WebAppFilterChain.doFilter (webappfilterchain.java:187)
At Com.caucho.server.dispatch.ServletInvocation.service (servletinvocation.java:265)
At Com.caucho.server.http.HttpRequest.handleRequest (httprequest.java:273)
At Com.caucho.server.port.TcpConnection.run (tcpconnection.java:682)
At Com.caucho.util.threadpool$item.runtasks (threadpool.java:743)
At Com.caucho.util.threadpool$item.run (threadpool.java:662)

At Java.lang.Thread.run (thread.java:619)


Looking for reasons and solutions on the Internet, now posted here:


Illegal character exception when parsing xml file (even if the character is in a CDATA segment): Org.xml.sax.SAXParseException:An Invalid XML character (UNICODE:0XB) was fo und in the CDATA section.
The reason: according to the standards of the consortium, some characters cannot appear in the XML file:
0x00-0x08
0x0b-0x0c
0x0e-0x1f
When parsing XML, these characters are encountered with errors

Workaround:
For XML files that are likely to be problematic, the characters are filtered and then parsed.


Public static string stripnonvalidxmlchars (string str)  {
  if  ( str == null | |   ". Equals (str))  {
    return str
  }
   Return str.replaceall ("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]" ", ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.