url = new URL(url_str);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream stream = connection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(stream);
doc.getDocumentElement().normalize();
Node node = doc.getElementsByTagName("baseName").item(0);
Log.d(TAG,">>>>"+node.getNodeValue());
当我在Web浏览器上尝试“url_str”时,它给了我下面的XML。如何解析从GET返回的XML(在Android中)
<files>
<file>
<fileId>441190</fileId>
<license>4</license>
<path>images</path>
<originalSource>
http://www.flickr.com/photos/stevendepolo/5165129565/sizes/m/
</originalSource>
<owner>Steven Depolo</owner>
<baseName>photo_5165129565_0ca9b101b0_t.jpg</baseName>
</file>
</files>
但是对于我的“node.getNodeValue()”输出,它返回null。但我需要获取baseName标记之间的字符串。