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());
When i try the “url_str” on web browser it gives me the following XML.
<files>
<file>
<fileId>441190</fileId>
<license>4</license>
<path>images</path>
<originalSource>
</originalSource>
<owner>Steven Depolo</owner>
<baseName>photo_5165129565_0ca9b101b0_t.jpg</baseName>
</file>
</files>
But for my output of “node.getNodeValue()” it returns null. But I need to get the string between baseName tag.
Try node.getTextContent(); instead of node.getNodeValue() this solved me most of the problems i had related to node value. sometimes the node value is not set instead the value is set to the text content.
Hope this would help.