The simplest way for Android pull to parse XML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.