The simplest way for Android pull to parse XML
<?xml version= "1.0" encoding= "Utf-8"?>
<doc>
<news>
<title><! [cdata[oscillator adjustment will be the next stage theme]]></title><time><! [cdata[2015-07-15]]></time><! [cdata[http://i1.hexunimg.cn/2014-12-08/171211297.jpg]]></img><id>177571349</id>< abstract><! [cdata[Market ended a retaliatory rebound, following yesterday's shock correction after a sharp decline today, the Shanghai Composite Index fell 3.03%, the gem refers to 4.99%, the bank and two barrels of oil once again become the main protection plate, the market back to the initial stage of the bailout. ]]></abstract>
</news>
<news>
<title><! [Cdata[-day fund: The core logic of bull market does not change]]></title><time><! [cdata[2015-07-13]]></time><! [cdata[http://i2.hexunimg.cn/2015-05-06/175569250.jpg]]></img><id>177477683</id>< abstract><! [Cdata[a stock Market experienced a "thrilling" depth adjustment, in the core 163503, fund bar Growth fund manager Xu Jiahan, "The plunge can be seen as a stress test before the full opening of China's capital market, a good lesson for managers and market participants." "]]></abstract>
</news>
</doc>
public static list<news> Getpull (String pid, int page) throws Exception {
string xmlstr = "";//Strings Read
list<news> List = new arraylist<news> ();
News news = null;
Xmlpullparser parser = Xml.newpullparser ();
Parser.setinput (new StringReader (XMLSTR));
while (Parser.next ()! = xmlpullparser.end_document) {
if (parser.geteventtype () = = Xmlpullparser.start_tag) {
String name = Parser.getname ();
if ("News". Equals (name)) {
news = new News ();
List.add (news);
} else if ("title". Equals (name)) {
News.settitle (Parser.nexttext ());
} else if ("Time". Equals (name)) {
News.settime (Parser.nexttext ());
} else if ("img". Equals (name)) {
news.setimg (Parser.nexttext ());
} else if ("id". Equals (name)) {
News.setid (Parser.nexttext ());
} else if ("abstract". Equals (name)) {
news.setabstracts (Parser.nexttext ());
}
}
}
return list;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The simplest way for Android pull to parse XML