扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
这篇文章将为大家详细讲解有关怎么在android中使用XStream对xml进行解析,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
创新互联从2013年成立,是专业互联网技术服务公司,拥有项目网站设计、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元运河做网站,已为上家服务,为运河各地企业和个人服务,联系电话:13518219792
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 Listapp_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
关于怎么在android中使用XStream对xml进行解析就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流