Android Pull解析xml
2010-09-17 00:16:00 来源:WEB开发网18. return price;
19. }
20. public void setPrice(float price) {
21. this.price = price;
22. }
23. @Override
24. public String toString(){
25. return this.id+":"+this.name+":"+this.price;
26. }
27. }
public class Book {
private int id;
private String name;
private float price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
@Override
public String toString(){
return this.id+":"+this.name+":"+this.price;
}
}
测试使用的是android的单元测试,代码如下:
Java代码
1. import java.io.InputStream;
2. import java.util.List;
3.
4. import android.test.AndroidTestCase;
5. import android.util.Log;
6.
7. import com.xtlh.cn.entity.Book;
8. import com.xtlh.cn.service.PullParseService;
9.
10. public class testPullParseService extends AndroidTestCase{
11. private static final String TAG = "testPullParseService";
12. public void testPull() throws Exception{
13. InputStream input = this.getClass().getClassLoader().getResourceAsStream("book.xml");
14. PullParseService pull = new PullParseService();
15. List< Book> books = pull.getBooks(input);
16. for(Book book : books){
17. Log.i(TAG,book.toString());
更多精彩
赞助商链接