XML解析 转载_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > XML解析 转载

XML解析 转载

 2011/1/18 8:05:26  googlelee  http://googlelee.javaeye.com  我要评论(0)
  • 摘要://连接服务器publicstaticInputStreamopenConn(Stringpath){HttpURLConnectionuc;URLurl;InputStreamis=null;try{url=newURL(path);//SocketAddressaddr=new//InetSocketAddress("10.0.0.172",80);//是代理地址//ProxytypeProxy=newProxy(Proxy.Type.HTTP,addr);//uc=
  • 标签:XML解析 XML 解析
//连接服务器
    public static InputStream openConn(String path) {
        HttpURLConnection uc;
        URL url;
        InputStream is = null;
        try {
            url = new URL(path);
            // SocketAddress addr = new
            // InetSocketAddress("10.0.0.172",80);//是代理地址
            // Proxy typeProxy = new Proxy(Proxy.Type.HTTP, addr);
            // uc = (HttpURLConnection) url.openConnection(typeProxy);
            uc = (HttpURLConnection) url.openConnection();
            uc.connect();
            is = uc.getInputStream();
            //uc.disconnect();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
        }
       
        return is;
    }


//XML解析部分
        InputStream is = openConn(你要解析的服务器的页面);
       
        //无法连接
        if (is == null)
            return false;
       
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return false;
        }
        Document document = null;
        try {
            document = builder.parse(is);
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

        Element rootElement = document.getDocumentElement();

        NodeList list = rootElement.getElementsByTagName("你的XML节点名");
发表评论
用户名: 匿名