我正在做一個android應用程序,我正在做一個httprequest來獲得一個XML文檔,我的httpEntity不會返回null,並且我正在嘗試使用documentbuilderfactory來解析該文件並從xml中獲取我需要的數據。我如何解析輸入流到文檔生成器?
我:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(URL);
httpPost.addHeader("Authorization", getAuthHeader());
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(is);
在這一點上我得到一個錯誤異常,看起來像這樣
org.xml.sax.SAXParseException: expected: /hr read: body (position:END_TAG @10:8 in [email protected])
有沒有人看到了這一點還是知道我在做什麼我無法找到是什麼問題,如果這是不夠的代碼,我可以提供更多,沒有更多的工作,只是http請求。 的「XML」的文件,我試圖讓這個樣子的
<ads>
<ad>
<id>6</id>
<minViews>10</minViews>
<duration>4</duration>
<actionUrl>URL</actionUrl>
<imageUrl>URL</imageUrl>
<impressionCount>0</impressionCount>
</ad>
<ads>
,那就是所有這些都是在文件中。我試圖在這兩個地方獲得網址。
當你說解析文件,你想擺脫它,一個字符串?一個節點? – Grammin 2011-02-22 17:51:23