最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
android 怎么用XStream解析xml
时间:2022-06-25 23:04:00 编辑:袖梨 来源:一聚教程网
1,要解析的xml文件文件
xml="n" + " ";n" + " n" + "1 n" + "burn n" + "1.0 n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "n" + " n" + "2 n" + "burn2 n" + "2.1 n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "n" + " n" + "3 n" + "burn3 n" + "3.2 n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "n" + " n" + "10.5 n" + "hhhhhhhh n" + "
2,新建xml文件对应的封装类
/**
*
xml数据对应的封装类(注意实体类和xml数据的对应关系,所有标签都得对应)
*/
@XStreamAlias("apps")//配置标签别名
public class AppBean {
@XStreamImplicit//忽略集合根节点
private List app_list;
//必须有无参构造方法
public AppBean() {
}
public AppBean(List app_list) {
this.app_list = app_list;
}
public List getApp_list() {
return app_list;
}
public void setApp_list(List app_list) {
this.app_list = app_list;
}
@XStreamAlias("app")
public static class App{
private long id;
private String name;
private String version;
@XStreamImplicit
private List infor_list;
public App() {
}
public App(long id, List infor_list, String name, String version) {
this.id = id;
this.infor_list = infor_list;
this.name = name;
this.version = version;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List getInfor_list() {
return infor_list;
}
public void setInfor_list(List infor_list) {
this.infor_list = infor_list;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@XStreamAlias("info")
public static class Infor{
private String message;
private double size;
public Infor() {
}
public Infor(String message, double size) {
this.message = message;
this.size = size;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
}
}
}
3,开始xml解析
XStream xStream=new XStream(); xStream.processAnnotations(AppBean.class);//声明使用注解的类 AppBean ab2= (AppBean) xStream.fromXML(xml);//xml-->Bean,只能解析为对象,不能解析为集合 String xml=xStream.toXML(AppBean.class)//Bean-->xml
相关文章
- dnf神界版本蓝拳装备搭配毕业攻略 神界版本蓝拳装备怎么选 11-29
- 流放之路S24速刷简单策略选择推荐 11-29
- 魔兽世界乌龟服防骑a怪一键宏指令分享 11-29
- 创世秩序全地图资料汇总 全地图区域中文名字对照 11-29
- 播种委员会全角色解锁攻略 全人物解锁位置详解 11-29
- 魔兽世界N服官网地址分享 Everlook服入口位置2024 11-29