這篇文章將為大家詳細(xì)講解有關(guān)怎么在android中使用XStream對(duì)xml進(jìn)行解析,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
創(chuàng)新互聯(lián)從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元運(yùn)河做網(wǎng)站,已為上家服務(wù),為運(yùn)河各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話: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文件對(duì)應(yīng)的封裝類
/** * xml數(shù)據(jù)對(duì)應(yīng)的封裝類(注意實(shí)體類和xml數(shù)據(jù)的對(duì)應(yīng)關(guān)系,所有標(biāo)簽都得對(duì)應(yīng)) */ @XStreamAlias("apps")//配置標(biāo)簽別名 public class AppBean { @XStreamImplicit//忽略集合根節(jié)點(diǎn) private Listapp_list; //必須有無(wú)參構(gòu)造方法 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,只能解析為對(duì)象,不能解析為集合 String xml=xStream.toXML(AppBean.class)//Bean-->xml
關(guān)于怎么在android中使用XStream對(duì)xml進(jìn)行解析就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。