parser 2.1 and 2.2

Posted by yaniv on Stack Overflow See other posts from Stack Overflow or by yaniv
Published on 2010-12-30T21:32:03Z Indexed on 2011/01/11 20:53 UTC
Read the original article Hit count: 280

Filed under:
|
|

hi

i using the follwing Code to retrive XML element text using getElementsByTagName

this code success in 2.2 and Failed in 2.1

any idea ?

URL metafeedUrl = new URL("http://x..../Y.xml")
URLConnection connection ;     
connection= metafeedUrl.openConnection();

HttpURLConnection  httpConnection = (HttpURLConnection)connection ;        
int resposnseCode= httpConnection.getResponseCode() ;

if (resposnseCode == HttpURLConnection.HTTP_OK) {

InputStream in = httpConnection.getInputStream();

DocumentBuilderFactory dbf ;
dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();


// Parse the Earthquakes entry 
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();

//ArrayList<Album> Albums = new ArrayList<Album>();


/* Returns a NodeList of all descendant Elements with a given tag name, in document order.*/

NodeList nl = docEle.getElementsByTagName("entry");

if (nl!=null && nl.getLength() > 0) {        
   for (int i = 0; i < nl.getLength(); i++) {

Element entry = (Element)nl.item(i);

/* Now on every property in Entry **/

Element title =(Element)entry.getElementsByTagName("title").item(0);          

*Here i Get an Error*
String album_Title = title.getTextContent();

Element id =(Element)entry.getElementsByTagName("id").item(0);         
String album_id = id.getTextContent(); // 

© Stack Overflow or respective owner

Related posts about android

Related posts about Xml