The data is as follows
<videonews><C:foreachItems= "${videos}"var= "Video" > <NewsID= "${video.getid ()}" > <title>${video.getname ()}</title> < Time>${video.gettime ()}</ Time> </News></C:foreach></videonews>
Get InputStream
String path= "Http://222.133.40.188:8080/androidServer/test"; URL URL=NewURL (path); HttpURLConnection Connection=(HttpURLConnection) url.openconnection (); Connection.setconnecttimeout (5000); Connection.setrequestmethod ("GET"); if(Connection.getresponsecode () ==200) {InputStream instream=Connection.getinputstream (); //get the file stream, convert the file to XML returnParsexml (instream); }Else{ return NULL; }
Parse inputstream--"xml
PrivateList<news> Parsexml (InputStream instream)throwsXmlpullparserexception, IOException {News news=NULL; List<News> newslist=NewArraylist<news>(); Xmlpullparser Pull=Xml.newpullparser (); Pull.setinput (instream,"Utf-8"); intEvent=Pull.geteventtype (); while(event!=xmlpullparser.end_document) { Switch(event) { CaseXmlpullparser.start_tag:if("News". Equals (Pull.getname ())) { intId=integer.parseint (Pull.getattributevalue (0)); News=NewNews (); News.setid (ID); }Else if("title". Equals (Pull.getname ())) {String name=Pull.gettext (); News.setname (name); }Else if("Time". Equals (Pull.getname ())) {String time=Pull.gettext (); News.settime (time); } Break; CaseXmlpullparser.end_tag:if("News". Equals (Pull.getname ())) {Newslist.add (news); } Break; } Event=Pull.next (); } returnnewslist; }
Android uses pull to parse XML data