Java/Android xml parsing -


i trying parse data google api:
http://gdata.youtube.com/feeds/base/videos?q=kittens&client=ytapi-youtube-search&v=2&start-index=1

like this

try {          documentbuilder db = dbf.newdocumentbuilder();         doc = db.parse(new inputsource(new stringreader(xml.trim())));   } catch (parserconfigurationexception e) {             system.out.println("xml parse error: " + e.getmessage());             return null; } catch (saxexception e) {             system.out.println("wrong xml file structure: " + e.getmessage());             return null; } catch (ioexception e) {             system.out.println("i/o exeption: " + e.getmessage());             return null; } 

and keep getting 'saxexception'.. doing wrong ?

the precise error message is:i/system.out(19026): wrong xml file structure: unexpected token (position:text null@1:104174 in java.io.stringreader@410c2448)

i have made , works me :

public static void readgdata(){        documentbuilderfactory dbf = documentbuilderfactory.newinstance();       documentbuilder db = null;       document doc = null;        try {          db = dbf.newdocumentbuilder();         doc = db.parse(new url("http://gdata.youtube.com/feeds/base/videos?q=kittens&client=ytapi-youtube-search&v=2&start-index=1").openstream());         system.out.println(doc.getelementsbytagname("name").getlength());          } catch (parserconfigurationexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (saxexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     }    } 

output in console :

26


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -