Xstream解析XML

复制代码
<oschina>
   <catalog>1</catalog>
   <newsCount>0</newsCount>
   <pagesize>20</pagesize>
   <newslist>
     <news>
       <id>72168</id>
       <title>
       <![CDATA[ PC-BSD 10.3 发布,桌面 BSD 系统 ]]>
       </title>
       <body>
       <![CDATA[ PC-BSD 10.3 发布了。 PC-BSD10.3使用了一个带有可选择的供替代的GRUB ... ]]> </body> <commentCount>0</commentCount> <author> <![CDATA[ oschina ]]> </author> <authorid>1</authorid> <pubDate>2016-04-05 07:35:28</pubDate> <url/> <newstype> <type>0</type> <authoruid2>1</authoruid2> <eventurl/> </newstype> </news> <news> <id>72168</id> <title> <![CDATA[ PC-BSD 10.3 发布,桌面 BSD 系统 ]]> </title> <body> <![CDATA[ PC-BSD 10.3 发布了。 PC-BSD10.3使用了一个带有可选择的供替代的GRUB ... ]]> </body> <commentCount>0</commentCount> <author> <![CDATA[ oschina ]]> </author> <authorid>1</authorid> <pubDate>2016-04-05 07:35:28</pubDate> <url/> <newstype> <type>0</type> <authoruid2>1</authoruid2> <eventurl/> </newstype> </news> </newslist> </oschina>
复制代码

Vo包   导xstream-1.4.7.jar包

/YueKao/src/com/bawei/vo/Good.java

复制代码
package com.bawei.vo;

import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("oschina")
public class Good { private String catalog; private String newsCount; private String pagesize; private Mynewslist newslist; public String getCatalog() { return catalog; } public void setCatalog(String catalog) { this.catalog = catalog; } public String getNewsCount() { return newsCount; } public void setNewsCount(String newsCount) { this.newsCount = newsCount; } public String getPagesize() { return pagesize; } public void setPagesize(String pagesize) { this.pagesize = pagesize; } public Mynewslist getNewslist() { return newslist; } public void setNewslist(Mynewslist newslist) { this.newslist = newslist; } @Override public String toString() { return "Good [catalog=" + catalog + ", newsCount=" + newsCount + ", pagesize=" + pagesize + ", newslist=" + newslist + "]"; } }
复制代码

/YueKao/src/com/bawei/vo/Mynewslist.java

复制代码
package com.bawei.vo;

import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("newslist")
public class Mynewslist { @XStreamImplicit(itemFieldName="news") List<Mynews> news; public List<Mynews> getNews() { return news; } public void setNews(List<Mynews> news) { this.news = news; } @Override public String toString() { return "Mynewslist [news=" + news + "]"; } }
复制代码

/YueKao/src/com/bawei/vo/Mynews.java

复制代码
package com.bawei.vo;

public class Mynews {
private String id; private String title; private String body; private String commentCount; private String author; private String authorid; private String pubDate; private String url; private Mynewstype newstype; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public String getCommentCount() { return commentCount; } public void setCommentCount(String commentCount) { this.commentCount = commentCount; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getAuthorid() { return authorid; } public void setAuthorid(String authorid) { this.authorid = authorid; } public String getPubDate() { return pubDate; } public void setPubDate(String pubDate) { this.pubDate = pubDate; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public Mynewstype getNewstype() { return newstype; } public void setNewstype(Mynewstype newstype) { this.newstype = newstype; } @Override public String toString() { return "Mynews [id=" + id + ", title=" + title + ", body=" + body + ", commentCount=" + commentCount + ", author=" + author + ", authorid=" + authorid + ", pubDate=" + pubDate + ", url=" + url + ", newstype=" + newstype + "]"; } }
复制代码

/YueKao/src/com/bawei/vo/Mynewstype.java

复制代码
package com.bawei.vo;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("newstype")
public class Mynewstype { private String type; private String authoruid2; private String eventurl; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getAuthoruid2() { return authoruid2; } public void setAuthoruid2(String authoruid2) { this.authoruid2 = authoruid2; } public String getEventurl() { return eventurl; } public void setEventurl(String eventurl) { this.eventurl = eventurl; } @Override public String toString() { return "Mynewstype [type=" + type + ", authoruid2=" + authoruid2 + ", eventurl=" + eventurl + "]"; } }
复制代码

解析

复制代码
     HttpUtils httpUtils = new HttpUtils();
        httpUtils.send(HttpMethod.POST, url , new RequestCallBack<String>() {

            @Override
            public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub  } @Override public void onSuccess(ResponseInfo<String> arg0) { // TODO Auto-generated method stub String result = arg0.result;

XStream stream = new XStream(); stream.processAnnotations(Good.class); Good good = (Good) stream.fromXML(result); List<Mynews> news = good.getNewslist().getNews(); adapter = new Adpter(getActivity(), news); my_xlist.setAdapter(adapter); } });
复制代码

转载于:https://www.cnblogs.com/wbp0818/p/5458581.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值