<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的更多相关文章

  1. Xstream 解析xml文件内容

    刚刚接手的一个项目,接到一个对接用户数据的需求,对方使用的是xml格式来传输文件,特此记下解析该类文件的方法 public interface XmlResolver<T> { XStre ...

  2. xstream解析xml时遇到特殊字符出错

    在xml中有"&"符号时,解析xml出错 解决办法: 将&替换成&

  3. XML解析---利用XStream解析xml数据及反构造Java对象

    XStream 是一个轻量级的.简单易用的开放源代码 Java库,用于将 Java 对象序列化为 XML 或者再转换回来.而且XStream还能将java对象转成其它格式,比如JSon. 需要用到的包 ...

  4. xstream 解析xml报文

    一.xml一种格式的数据转换为对象 pom.xml引入 <!--javaBean和XML的双向转换--> <dependency> <groupId>com.tho ...

  5. (转载)XML解析之-XStream解析

    转载来源:http://hwy584624785.iteye.com/blog/1168680 本例使用XStream生成一个xml文件,再发序列化xml文件内容. XStream是一个简单的类库,可 ...

  6. java生成解析xml的另外两种方法Xstream

    Xstream生成和解析xm和JAXB生成和解析xml的方法. 一,Xstream Xstream非jdk自带的,需要到入Xstream-1.4.3.jar和xpp3_min-1.1.4.jar 1. ...

  7. 使用XStream解析复杂XML并插入数据库(二)

    标注黄色地方:我需要加深学习!!! 我写的是webservice,目前具体写webservice的步骤我还不清楚, 整理完小知识开始整理webservice! 针对以下格式的XML进行解析 <? ...

  8. 使用XStream解析复杂XML并插入数据库(一)

    环境: Springboot+mysql 我只想说jpa真的超级好用,准备深入研究一下~ 导入依赖: <dependency> <groupId>org.projectlomb ...

  9. 浅谈 Java 主流开源类库解析 XML

    在大型项目编码推进中,涉及到 XML 解析问题时,大多数程序员都不太会选用底层的解析方式直接编码. 主要存在编码复杂性.难扩展.难复用....,但如果你是 super 程序员或是一个人的项目,也不妨一 ...

随机推荐

  1. 多边形裁剪的Sutherland-Hodgman算法

    多边形裁剪是渲染管线中重要的一个子阶段,它将视截体外的多边形去除.一种简单的裁剪策略是一旦发现一个顶点在裁剪区域以外,就立刻丢弃该多边形.更加精细的做法则是,将原来的多边形拆为多个不跨越边界的多边形, ...

  2. Java Mybatis 框架入门教程

    一.Mybatis介绍 MyBatis是一款一流的支持自定义SQL.存储过程和高级映射的持久化框架.MyBatis几乎消除了所有的JDBC代码,也基本不需要手工去 设置参数和获取检索结果.MyBati ...

  3. JSON 与 JSONP

    JSON (JavaScript Object Notation) is a lightweight data-interchange format. 即 JSON 是一种轻量级的数据交换格式. 1. ...

  4. 如何使用Google Map API开发Android地图应用

    两年前开发过的GoogleMap已经大变样,最近有项目要用到GoogleMap,重新来配置Android GoogleMap开发环境,还真是踩了不少坑. 一.下载Android SDK Manager ...

  5. Multiprocessor Operating System Design Considerations SYMMETRIC MULTIPROCESSORS

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION An SMP operating syst ...

  6. 【java基础学习】IO流

    IO流 字节流InputStream和OutputStream 字符流Writer和Reader 装饰模式

  7. Java-马士兵动态代理模式

    Java-马士兵动态代理模式 模拟jdk的动态代理的实现原理, 这些东西没有必要写出来,写项目的时候一般用不上,主要是为了面试和理解原理: java动态代理有什么作用 作用非常大,在很多底层框架中都会 ...

  8. PyInstaller打包步骤简记

    pyinstaller 下载地址:http://www.pyinstaller.org/ 下载后用cmd进入解压文件夹 python setup.py install 安装. 最近用pyinstall ...

  9. QHash

    #include <QCoreApplication> #include<QHash> #include<QDebug> int main(int argc, ch ...

  10. easyui 分页 MVC

    View <script type="text/javascript"> var dd; var grid; $(function () { var queryData ...