0

我正在尝试从 Http 获取 Rss XML,我使用了这两个数学:

public String getXMLfromUrl(String url){
    String xml = null;
    try{
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpclient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);
    }catch(Exception e){
        Log.e(" getXMLfromUrl : "," ",e);
    }
    return xml;
} 


public Document getDomElement(String xml){
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try{
        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(xml);
            doc.getDocumentElement().normalize();
    }catch(Exception e){
        Log.e(" getDomElement : "," ",e);
    }
    return doc;
}

但是我有一个问题,第一个方法没有返回所有 XML 字符串,所以字符串不是 XML 格式,我认为我的 XML 流太长或者因为我包含 /n 或者可能但因为包含阿拉伯字符,所以第二个 Mathod 抛出 java.net.malformedurlexception 协议未找到 android ,或者我认为....

请帮助我

4

0 回答 0