说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

JDOM高手看过来!

编辑:说三道四文库 发布时间:2018-02-21 03:52
HTML文档下载 WORD文档下载 PDF文档下载
用JDOM解析下面的XML文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
    <enterprise-beans>
        <session>
            <display-name>Enterprise1</display-name>
            <ejb-name>Deposit</ejb-name>
            <home>wsejb.DepositHome</home>
            <remote>wsejb.Deposit</remote>
            <ejb-class>wsejb.DepositBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
        </session>
    </enterprise-beans>
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>Deposit</ejb-name>
                <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    </assembly-descriptor>
</ejb-jar>

源程序如下:

package wsclient.rmi;

import java.util.HashMap;
import org.jdom.input.*;
import org.jdom.*;

public class Test {
  public static void main(String[] args) {
    HashMap brh = new HashMap();
                SAXBuilder sax = new SAXBuilder(false);
               // DOMBuilder sax = new DOMBuilder(false);
                try {
                        Document doc = sax.build("D:\\WSAI\\projects\\ejb\\Demo1\\ejb-jar.xml");
                        //get the root element
                        Element root = doc.getRootElement();
                        root.getName();
                        //get required Fields
                        Element session = root.getChild("enterprise-beans")
                                        .getChild("session");
                        Element temp = session.getChild("remote");
                        brh.put("remote", temp.getText());

                        temp = session.getChild("home");
                        brh.put("home", temp.getText());

                        temp = session.getChild("ejb-class");
                        brh.put("ejb-class", temp.getText());
                } catch (JDOMException jex) {
                        jex.printStackTrace();
                        brh = null;
                }

  }
}

结果出错如下:
org.jdom.JDOMException: java.sun.com: java.sun.com

at org.jdom.input.SAXBuilder.build(SAXBuilder.java:323)

at org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)

at wsclient.rmi.Test.main(Test.java:13)

Root cause: java.net.UnknownHostException: java.sun.com

at java.net.InetAddress.getAllByName0(InetAddress.java:571)

at java.net.InetAddress.getAllByName0(InetAddress.java:540)

at java.net.InetAddress.getByName(InetAddress.java:449)

at java.net.Socket.<init>(Socket.java:100)

at sun.net.NetworkClient.doConnect(NetworkClient.java:50)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)

at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)

at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)

at sun.net.www.http.HttpClient.New(HttpClient.java:289)

at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:408)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:501)

at java.net.URL.openStream(URL.java:798)

at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)

at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)

at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)

at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)

at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)

at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)

at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

at org.jdom.input.SAXBuilder.build(SAXBuilder.java:305)

at org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)

at wsclient.rmi.Test.main(Test.java:13)

好像提示验证没通过,可是我在程序里已经设置不验证了啊,

SAXBuilder sax = new SAXBuilder(false);

为什么会这样呢?
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘