简直让我愤怒,解析xml时出现异常,直接找不到北了!诸位英雄,救命!

jinyunliu 2003-10-16 03:40:43
程序代码段:
Document document= new DocumentImpl();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //获取一个xml文档的解析器
//解析XML文件生成DOM文档的接口类,以便访问DOM。
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
}
catch (ParserConfigurationException ex) {
}
File f=new File("D:\\temp11.xml");
try {
document = builder.parse(f);就这里出异常
}
catch (IOException ex1) {
System.out.print("iooo");
}
catch (SAXException ex1) {
ex1.printStackTrace() ;
System.out.print("Saxxxx");
}
Element element =document.getDocumentElement();
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
Element root = svgGenerator.getRoot();
....................

出的异常为:
java.net.ConnectException: Connection timed out: connect

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)

at org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2870)

at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1167)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)

at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)

at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:151)

at slofsoft.graphics.wellchart.Servlet1.doGet(Servlet1.java:37)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)

at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)

at java.lang.Thread.run(Thread.java:536)

Saxxx
...全文
129 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sadenxu 2003-10-21
  • 打赏
  • 举报
回复
首先感谢rex0y(没学好九阳神功就妄想几小时练成乾坤大挪) 同志,受到rex0y的启发,因为我刚开始以为是程序问题,因为我以前也做过类似的东西,后来我才觉得应该是XML文件的问题,当然<!DOCTYPE ……> 先去掉,因为DTD有可能找不到,现在再试试!
yinwaner 2003-10-21
  • 打赏
  • 举报
回复
建议使用JDOM
rex0y 2003-10-20
  • 打赏
  • 举报
回复
这应该是DTD 的问题, 如果xml 开头有doctype 申明, 一般里面会是个DTD的url
所以你一解析就会先连这个url导致
java.net.ConnectException: Connection timed out: connect
fanth 2003-10-20
  • 打赏
  • 举报
回复
DTD问题,没有找到地址。
leowu 2003-10-20
  • 打赏
  • 举报
回复
不一定要用DTD的话,就去掉他,应该就好了。
jinyunliu 2003-10-17
  • 打赏
  • 举报
回复
楼上兄弟,"其他事情"?,没有啊,就是想从“D:\\temp11.xml”中解析出根节点,用来画svg图的
etre 2003-10-17
  • 打赏
  • 举报
回复
你还做了其他事吗
java.net.ConnectException: Connection timed out: connect
wellsoon 2003-10-16
  • 打赏
  • 举报
回复

为什么不用jdom呢,操作起来很方便。

public static Document Readfromfile(String filePath) {
try {
java.io.File XmlFile;
String XmlFileName;
XmlFile = new java.io.File(filePath);
SAXBuilder builder = new SAXBuilder();
Document anotherDocument = builder.build(new File(filePath));
return anotherDocument;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}

jinyunliu 2003-10-16
  • 打赏
  • 举报
回复
我在google上搜到一个页面,看了半天,不知道啥东东,我用JBuilder编译,tomcat用自带的:


A. Common Questions

If running an installation script produces the following error message:



java.net.ConnectException: Connection timed out

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)

at org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2870)

at ...



That probably means all outgoing HTTP traffic from machineA is blocked unless it goes through a specific proxy.

You need to update the file data/runtime/runtime.local.properties in the module iceni-bootstrap to define the following properties:

http.proxyHost=<name of the cache>
http.proxyPort=<port of the cache>


You might also need to define the property http.nonProxyHost . The properties http.proxyHost and http.proxyPort indicate the proxy server and port that the http protocol handler will use. http.nonProxyHosts indicates the hosts which should be connected too directly and not through the proxy server. More informations on how to set these properties can be found at http://java.sun.com/j2se/1.4.1/docs/guide/net/properties.html .

The properties defined in that file will be set both by the bootstrap mechanism and the application started through the bootstrap

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧