<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. 目录的文件权限-X

    所有目录务必保持具有X权限(可执行权限)!!,否则无法进入该目录及子目录,且无法读取该目录及子目录下的文件或子目录

  2. HDU5769 Substring(后缀数组)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5769 #include <iostream> #include <stdio.h> ...

  3. 错误信息:attempt to create saveOrUpdate event with null entity

    错误信息:attempt to create saveOrUpdate event with null entity; 这个错误网上答案比较多,我也不多说了. 我遇到的问题是在前台传过来的参数是nul ...

  4. 实战Java虚拟机之四:提升性能,禁用System.gc() ?

    今天开始实战Java虚拟机之四:"禁用System.gc()". 总计有5个系列 实战Java虚拟机之一“堆溢出处理” 实战Java虚拟机之二“虚拟机的工作模式” 实战Java虚拟 ...

  5. 完成对数据库的CRUD操作

    PS:查询相对复杂,要处理结果集,增删改则不用. package it.cast.jdbc; import java.sql.Connection; import java.sql.ResultSet ...

  6. 百钱买百鸡问题 php版本

    /* * 百钱买百鸡问题 * * 我国古代数学家张丘建在<算经>一书中曾提出过著名的“百钱买百鸡”问题,该问题叙述如下:鸡翁一,值钱五:鸡母一,值钱三:鸡雏三,值钱一:百钱买百鸡,则翁.母 ...

  7. 在网页中让Backspace按键不可作为退回使用

    这也是转载的,让BackSpace按键不可作为退回使用,在textbox中设置readonly时,将退回禁用. <script type="text/javascript"& ...

  8. Struts2 输入格式自动校验的一些注意事项

    Struts2 在配置格式校验的文件的时候,格式是XXAction-validation.xml,具体如下. 需要注意的是: field的name属性的值,必须要和jsp中表单提交的name一致.千万 ...

  9. SVN中trunk、branches、tag的使用

     我相信初学开发在SVN作为版本管理时,都估计没可能考虑到如何灵活的运用SVN来管理开发代码的版本,下面我就摘录一篇文章来简单说明SVN里的trunk,branched,tags这个三个文件目录的用法 ...

  10. Matlab中常用机器学习函数

    更多内容请参考http://cn.mathworks.com/help/stats/index.html?s_cid=doc_ftr. Naive Bayes(朴素贝叶斯) Factor = Naiv ...