<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. SQl中的char,varcher,nvarchar,txt

    CHAR    char是定长的,在字段建立时,空间就固定了,不管是否插入值(NULL也包含在内),都占用字符的空间.例如: char(8),输入字符小于8,后面补空值.输入字符大于8时,会截取.CH ...

  2. 那些年一起用过的iOS开发利器[4月2号更新]

    4月2号新增Runscope. Runscope 这是一家专注于API工具开发的公司,其创始人John Sheehan曾就职于IFTTT和Twilio.Runscope是一款集调试.测试于一身的网络服 ...

  3. WPF整理-XAML构建后台类对象

    1.XAML 接触WPF的第一眼就是XAML---XAML是用来描绘界面的.其实不然! "Actually, XAML has nothing to do with UI. It's mer ...

  4. Azure Active Directory Connect密码同步问题

    这几天一直在弄O365与本地域账号的密码同步问题.由于微软即将用Azure Active Directory Connect(以下简称AADC)这个同步工具替代之前的DirSync,所以我也研究了下这 ...

  5. 关于web.config中<customErrors>节点说明

    <customErrors>节点用于定义一些自定义错误信息的信息.此节点有Mode和defaultRedirect两个属性,其中defaultRedirect属性是一个可选属性,表示应用程 ...

  6. JQuery控制滚动条滚动到指定位置

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. java 反射获取类的属性 类型 名称和值

    /** * 获取属性类型(type),属性名(name),属性值(value)的map组成的list * */ private List getFiledsInfo(Object o){ Field[ ...

  8. 在eclipse中创建一个Maven项目

    1. 首先判断eclipse有没有自带Maven Window –> Perferences 如果有Maven,那就是自带了maven插件,如果没有,需要自行安装. 2.配置maven 2.1. ...

  9. iOS应用程序的生命周期

    iOS应用程序一般都是由自己编写的代码和系统框架(system frameworks)组成,系统框架提供一些基本infrastructure给所有app来运行,而你提供自己编写的代码来定制app的外观 ...

  10. golang map getkeys

    golang 获取map的keys package main import "fmt" import "reflect" func main() { abc : ...