gpt4 book ai didi

java - Documentbuilder.parse() 的问题

转载 作者:行者123 更新时间:2023-12-01 15:46:03 25 4
gpt4 key购买 nike

我正在尝试从给定的 URL 解析一些 XML。代码如下:

try {

URL myUrl = new URL(sURL);
URLConnection c = myUrl.openConnection();

c.setConnectTimeout(5000);
c.setReadTimeout(5000);

org.w3c.dom.Document doc = readXml(c.getInputStream());}

/////

public static org.w3c.dom.Document readXml(InputStream is) throws SAXException, IOException,
ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setIgnoringComments(false);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse(is);
return doc;
}

我有一个异常(exception):

java.net.UnknownHostException: subUrL.mydomain.com at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:196) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:378) at java.net.Socket.connect(Socket.java:537) at sun.net.NetworkClient.doConnect(NetworkClient.java:170) at sun.net.www.http.HttpClient.openServer(HttpClient.java:395) at sun.net.www.http.HttpClient.openServer(HttpClient.java:530) at sun.net.www.http.HttpClient.(HttpClient.java:234) at sun.net.www.http.HttpClient.New(HttpClient.java:307) at sun.net.www.http.HttpClient.New(HttpClient.java:324) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:855) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:740) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:721) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1044) at com.eoffice.xml.RSSReader.getLimitedRSS(RSSReader.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:321) at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) at com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82) at com.ibm.jscript.std.FunctionObject._executeFunction(FunctionObject.java:261) at com.ibm.jscript.std.FunctionObject.executeFunction(FunctionObject.java:185) at com.ibm.jscript.std.FunctionObject.call(FunctionObject.java:171) at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) at com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82) at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119) at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139) at com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435) at com.ibm.jscript.JSExpression.access$1(JSExpression.java:424) at com.ibm.jscript.JSExpression$2.run(JSExpression.java:414) at java.security.AccessController.doPrivileged(AccessController.java:284) at com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410) at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251) at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234) at com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:220) at com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:192) at com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:78) at javax.faces.component.UIOutput.getValue(UIOutput.java:159) at com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1073) at com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:91) at com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:153) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005) at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:809) at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1272) at com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1210) at com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:635) at com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:320) at com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:355) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120) at com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:264) at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:219) at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:193) at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:154) at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:137) at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:86) at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:538) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1140) at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:803) at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:758) at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:527) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1124) at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:513) at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:342) at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:304) at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:261) at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:291)

当我尝试在浏览器中打开相同的 URL 时,结果是一个漂亮的 RSS-XML 页面。有人知道这可能是什么吗?在错误中我删除了实际的 URL。输入网址的格式为:http://subdomain.domain.com/somepath/somebase.nsf/form?ReadForm&newsCode=code

最佳答案

java.net.UnknownHostException: subUrL.mydomain.com 指出存在 DNS 问题。我假设您已用示例替换了实际的 URL。在这种情况下,请检查您的网络设置并检查 JVM 是否可以正确解析 URL。

关于java - Documentbuilder.parse() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com