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 程序员或是一个人的项目,也不妨一 ...
随机推荐
- [转载]C++堆栈的入门学习
申明: 转自 http://www.cnblogs.com/pengshao/archive/2011/12/26/2301461.html 头文件stackDemo.h #pragma o ...
- linux中test与[ ]指令的作用
linux中test与[ ]指令的作用: 在Linux中,test和[ ]功能是一样的,类似于c语言中的( ).不过Linux的test和[ ]是指令.在和if或者while联用时要用空格分开.
- centos 安装 opencv-3.1.0
官方安装教程 http://docs.opencv.org/3.1.0/d9/d52/tutorial_java_dev_intro.html#gsc.tab=0 注意要先安装jdk和apache a ...
- [dpdk] 熟悉SDK与初步使用 (一)(qemu搭建实验环境)
搭建实验环境: troubleshoot 第一步加载驱动 第二步切换驱动 使用了所有qemu支持的卡 [tong@T7:~/VM/dpdk] % cat start.sh sudo qemu-syst ...
- 从一道NOI练习题说递推和递归
一.递推: 所谓递推,简单理解就是推导数列的通项公式.先举一个简单的例子(另一个NOI练习题,但不是这次要解的问题): 楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可 ...
- h5移动版云胶片系统
h5移动版云胶片系统. 最近开了一个医疗用的云胶片,可以对图片放大.图片缩小,图片移动,图片调窗,图片切换,图片播放,图片变灰等等功能.如下图:
- Ubuntu 14.04 编译安装 husky
简介 Husky是一个大数据分布式开发框架,用C++开发,因为粗粒度(coarse-grained)平台(如Spark,Hadoop,Flink)MR耗时太大,然后细粒度(fine-grained)平 ...
- sparksql---通过pyspark实现
上次在spark的一个群里面,众大神议论:dataset会取代rdd么? 大神1:听说之后的mlib都会用dataset来实现,呜呜,rdd要狗带 大神2:dataset主要是用来实现sql的,跟ml ...
- log4j+mongodb
maven 配置: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java ...
- win7下安装mysql5.7[zip包]
原本以为很简单的安装,结果卡在一个环节,此文记录安装步奏. 1.下载mysql-5.7.16-winx64.zip 安装包 地址:http://cdn.mysql.com//Downloads/MyS ...