在一台机器上获取 JDOMException 但相同的 xml 在另一台机器上工作正常
我正在点击 xml 并将响应返回到输入流中。该 xml 位于远程服务器上。
每当我在服务器上运行代码时,它都会给我 JDOMException,但是相同的代码,我在本地计算机上运行并在远程服务器上点击相同的 xml,它运行良好。
URL url = new URL("http://testwww.net/xml/android.xml");
InputStream stream = url.openStream();
try {
SAXBuilder builder = new SAXBuilder(false);
xmlDocument = builder.build(stream);
} catch (JDOMException e) {
throw new Exception("unable to read android listing document", e);
}
堆栈跟踪为
org.jdom.input.JDOMParseException:第 1 行出错:在公共标识符中发现无效的 XML 字符(Unicode:0x5c)。 在 org.jdom.input.SAXBuilder.build(SAXBuilder.java:468) 在 org.jdom.input.SAXBuilder.build(SAXBuilder.java:770) 在 com.cellularsouth.dao.appsdetails.GetAndroidApps.getCategoriesData(GetAndroidApps.java:42) 在 com.cellularsouth.discovercenter.appsdetails.web.AndroidApps.androidCategoryData(AndroidApps.java:28) 在 com.cellularsouth.servlets.discovercentercontroller.handleRequestInternal(discovercentercontroller.java:62) 在 org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) 在org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) 在 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:743) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:856) 在 weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) 在 weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) 在 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283) 在 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175) 在 weblogic.servlet.internal.WebAppServletContext$ServletInspirationAction.run(WebAppServletContext.java:3231) 在 weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) 在 weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) 在 weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2002) 在 weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1908) 在 weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1362) 在 weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) 在 weblogic.work.ExecuteThread.run(ExecuteThread.java:181) 引起原因:org.xml.sax.SAXParseException:在公共标识符中发现无效的 XML 字符(Unicode:0x5c)。 在 org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(来源未知) 在 org.apache.xerces.util.ErrorHandlerWrapper.fatalError(来源未知) 在 org.apache.xerces.impl.XMLErrorReporter.reportError(来源未知) 在 org.apache.xerces.impl.XMLErrorReporter.reportError(来源未知) 在 org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
它在第一行给了我错误,但实际上我在这里看不到任何问题。 XML 是
--------------------------继续-----
我无法弄清楚这里的问题是什么,相同的 xml在一台机器上运行良好,但在另一台机器上运行不佳。 xml没有问题。
请帮我。
谢谢惠普
I am hitting an xml and getting the response back in inputstream. This xml is on the remote server.
Whenever I am running my code on the server, it gives me JDOMException,but the same code, I am running on my local machine and hitting the same xml on remote server, it is running fine.
URL url = new URL("http://testwww.net/xml/android.xml");
InputStream stream = url.openStream();
try {
SAXBuilder builder = new SAXBuilder(false);
xmlDocument = builder.build(stream);
} catch (JDOMException e) {
throw new Exception("unable to read android listing document", e);
}
Stack Trace is
org.jdom.input.JDOMParseException: Error on line 1: An invalid XML character (Unicode: 0x5c) was found in the public identifier.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:468)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:770)
at com.cellularsouth.dao.appsdetails.GetAndroidApps.getCategoriesData(GetAndroidApps.java:42)
at com.cellularsouth.discovercenter.appsdetails.web.AndroidApps.androidCategoryData(AndroidApps.java:28)
at com.cellularsouth.servlets.discovercentercontroller.handleRequestInternal(discovercentercontroller.java:62)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3231)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2002)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1908)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1362)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Caused by: org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x5c) was found in the public identifier.
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)
It gives me error on first line that but actually i cant see any problem here.
XML is
--------------------------continue-----
I am not able to figure out what can be the problem here, that the same xml is running fine on one machine and not on other. There is no problem with the xml.
Please help me.
Thanks Hp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到问题了。问题是,我的服务器在 UNIX 上运行,而我的本地主机在 Windows 上运行。因此,xml 没有正确编码,因此 Unix 无法找到一些字符,并且它给了我解析错误,但它们在 Windows 上渲染得很好。
I got the problem. The problem was that, my server was running in UNIX and my localhost is running on Windows. So, the xml was not properly encoded so Unix was not able to find some chacters and it was giving me Parsing error but they were rendering fine on Windows.