使用Dom解析解析rss xml文件时为什么会出现IoException?

时间:2011-06-07 09:59:35

标签: android rss xml-parsing

我在Android中使用DOM解析来解析rss.xml文件。在使用网址InputStream解析文档时,我收到了IOException。造成这种情况的原因是什么?

public static Document postPage(String url, String data ,boolean isPost) {
        String ret = null;
        HttpResponse response = null;
        BasicHttpContext localContext = null;
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpPost httpPost = null ;
        HttpGet request = null;

        if(Constants.LOG)Log.d("URL in util is : ",""+url);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),new UsernamePasswordCredentials(Constants.AUTHENTICATION_USERNAME, Constants.AUTHENTICATION_PASSWORD));



            if(Constants.LOG)Log.d("In Http get", "URL is : "+url);
            request = new HttpGet();

            try {
                request.setURI(new URI(url));

                response = httpClient.execute(request);

                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    if(Constants.LOG)Log.d("ClientProtocolException", ""+e);
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    if(Constants.LOG)Log.d("IOException", ""+e);
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    if(Constants.LOG)Log.d("URISyntaxException", ""+e);
                    e.printStackTrace();
                }






        try {

                response = httpClient.execute(request);
            }


        } catch (ClientProtocolException e) {
            if(Constants.LOG)Log.d("UTIL", "postPage ClientProtocolException Ex::"+e);
            return null;
        } catch (IOException e) {
            if(Constants.LOG)Log.d("UTIL", "postPage IOException Ex::"+e);
            return null;
        } 

        ret = response.getStatusLine().toString();
        if(Constants.LOG)Log.d("UTIL", "postPage STATUS::"+ret);

        HttpEntity he = response.getEntity();
        InputStream inStream = null;
        Document docElement = null;;
        DocumentBuilderFactory docBuilderFactory = null;
        DocumentBuilder docBuilder = null;

        try {
            URL Url = new URL(url);

            inStream =he.getContent();


            docBuilderFactory =DocumentBuilderFactory.newInstance();
            docBuilder = docBuilderFactory.newDocumentBuilder();
            docElement = docBuilder.parse(inStream);
            if(Constants.LOG)Log.d("UTIL", "isStream available::"+inStream.available());

        } catch (IOException e) {
            // TODO Auto-generated catch block
            if(Constants.LOG)Log.d("UTIL", "postPage IOException1 Ex::"+e);

        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{

            try {
                inStream.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return docElement;
    }

我在以下情况获得例外:

docElement = docBuilder.parse(inStream);

0 个答案:

没有答案