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); }
});
Xstream解析XML的更多相关文章
- Xstream 解析xml文件内容
刚刚接手的一个项目,接到一个对接用户数据的需求,对方使用的是xml格式来传输文件,特此记下解析该类文件的方法 public interface XmlResolver<T> { XStre ...
- xstream解析xml时遇到特殊字符出错
在xml中有"&"符号时,解析xml出错 解决办法: 将&替换成&
- XML解析---利用XStream解析xml数据及反构造Java对象
XStream 是一个轻量级的.简单易用的开放源代码 Java库,用于将 Java 对象序列化为 XML 或者再转换回来.而且XStream还能将java对象转成其它格式,比如JSon. 需要用到的包 ...
- xstream 解析xml报文
一.xml一种格式的数据转换为对象 pom.xml引入 <!--javaBean和XML的双向转换--> <dependency> <groupId>com.tho ...
- (转载)XML解析之-XStream解析
转载来源:http://hwy584624785.iteye.com/blog/1168680 本例使用XStream生成一个xml文件,再发序列化xml文件内容. XStream是一个简单的类库,可 ...
- java生成解析xml的另外两种方法Xstream
Xstream生成和解析xm和JAXB生成和解析xml的方法. 一,Xstream Xstream非jdk自带的,需要到入Xstream-1.4.3.jar和xpp3_min-1.1.4.jar 1. ...
- 使用XStream解析复杂XML并插入数据库(二)
标注黄色地方:我需要加深学习!!! 我写的是webservice,目前具体写webservice的步骤我还不清楚, 整理完小知识开始整理webservice! 针对以下格式的XML进行解析 <? ...
- 使用XStream解析复杂XML并插入数据库(一)
环境: Springboot+mysql 我只想说jpa真的超级好用,准备深入研究一下~ 导入依赖: <dependency> <groupId>org.projectlomb ...
- 浅谈 Java 主流开源类库解析 XML
在大型项目编码推进中,涉及到 XML 解析问题时,大多数程序员都不太会选用底层的解析方式直接编码. 主要存在编码复杂性.难扩展.难复用....,但如果你是 super 程序员或是一个人的项目,也不妨一 ...
随机推荐
- hdu 4898 The Revenge of the Princess’ Knight
传送阵:http://acm.hdu.edu.cn/showproblem.php?pid=4898 题目大意:一个首尾相连的字符串,将其分为k个子串,使得最大的字串最小 将所有子串排序,输出第k小即 ...
- IOS网络第二天 - 06-POST请求
************POST请求 #import "HMViewController.h" #import "MBProgressHUD+MJ.h" @in ...
- PHP性能监测的工具介绍 - XHProf
http://segmentfault.com/a/1190000003509917 http://www.cnblogs.com/casatwy/archive/2013/01/17/2865241 ...
- Proguard参数
参数:?-include?{filename}?从给定的文件中读取配置参数?-basedirectory?{directoryname}?指定基础目录为以后相对的档案名称?-injars?{class ...
- mysql排序时索引的注意事项
参考 'mysql高性能'
- 微信小程序wafer
1.Centos 重启nginx systemctl restart|stop|start|status nginx.service status是状态,可以看出nginx是否正在运行! system ...
- pt-table-checksum和pt-heartbeat的使用
一.pt-table-checksum 1.主从上均新建账户GRANT SELECT, PROCESS, SUPER, REPLICATION SLAVE ON *.* TO 'checksum'@' ...
- (转)微信小程序破解IDE
1.IDE下载 微信web开发者工具,本人是用的windows 10 x64系统,用到以下两个版本的IDE安装工具与一个破解工具包: wechat_web_devtools_0.7.0_x64.exe ...
- docker-freebsd-20150625
http://www.docker.org.cn/book/docker/prepare-docker-1.html https://wiki.freebsd.org/Docker pkg insta ...
- iOS10 导航条,这个二狗子变了...踩坑
1.iOS10导航透明要转换一个透明image UIImage *image = IsDeviceVersionIOS10 ? [WeUtils imageWithColor:[UIColor cle ...