当前位置: 代码迷 >> Android >> ,帮忙解析<msgContent></msgContent>里面的内容用pull方法,完美解决给50分
  详细解决方案

,帮忙解析<msgContent></msgContent>里面的内容用pull方法,完美解决给50分

热度:12   发布时间:2016-04-28 01:44:45.0
求助,帮忙解析<msgContent></msgContent>里面的内容用pull方法,完美解决给50分
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message xmlns="https://mobile.XXXXXXXX">
<version>4.0</version>
<appVersion>MP_AND_APP_X1_99BILL_01_05_00_15033117_02</appVersion>
<bizType>S110</bizType><responseCode>00</responseCode><responseMsg>成功</responseMsg>
<deviceInfo><mac>81:7a:88:09:97:23</mac><imei>99000291204203</imei><imsi>460031206106299</imsi>
</deviceInfo><userName>12345678910</userName>
<msgContent>
<appInfo><appType>Android</appType>
<latestAppVersion>1.6.0.12</latestAppVersion>
<latestAppVersionUrl>https://XXXXXXXXXX.apk</latestAppVersionUrl>
<appFlag>2</appFlag></appInfo>
</msgContent>
</message>
------解决思路----------------------
 public void xml() throws XmlPullParserException, IOException{
     String str = "";
     XmlPullParser xmlPullParser= Xml.newPullParser();
        xmlPullParser.setInput(getResources().openRawResource(R.raw.file),"UTF-8");     
        int type=xmlPullParser.getEventType();
        while(type!=XmlPullParser.END_DOCUMENT){
            switch (type) {
            case XmlPullParser.START_DOCUMENT: 
            {
//                updateinfolist =new ArrayList<msgContent>();
            }
            break;
            case XmlPullParser.START_TAG:
                    String tag=xmlPullParser.getName();
//                    if(tag.equalsIgnoreCase("appInfo")){
//                        updateinfo=new msgContent();
//                        statrtappInfo=true;
//                    }
                if(tag.equalsIgnoreCase("latesAppVersion")){
//                   updateinfo.setLatestAppVersion(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }else if(tag.equalsIgnoreCase("appVersion")){
//                    updateinfo.setAppVersion(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }if(tag.equalsIgnoreCase("responseCode")){
//                    updateinfo.setResponseCode(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }if(tag.equalsIgnoreCase("appFlag")){
//                    updateinfo.setAppFlag(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }if(tag.equalsIgnoreCase("appType")){
//                    updateinfo.setAppType(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }if(tag.equalsIgnoreCase("latestAppVersionUrl")){
//                    updateinfo.setLatestAppVersionUrl(xmlPullParser.getText());
                 str +="=====" + xmlPullParser.nextText()+";" ;
                }
                break;
            case XmlPullParser.END_TAG:
                if(xmlPullParser.getName().equals("appInfo")){
//                    updateinfolist.add(updateinfo);
//                    updateinfo=null;
                }
           }
            type=xmlPullParser.next(); 
        }
        System.out.print(str);
   }
成功拿到数据
------解决思路----------------------
引用:
大神,如果这个方法有参数呢
public List<msgContent> parse(String result){}

就像这样的,下面那个setInput又怎么办呢??
我是想把这个方法封装起来,然后再别处调用它

谢谢你啊先给分给你
 public void xml(int id) throws XmlPullParserException, IOException{
     String str = "";
     XmlPullParser xmlPullParser= Xml.newPullParser();
        xmlPullParser.setInput(getResources().openRawResource(id),"UTF-8");
就这样吧他需要的参数传递进去就ok
  相关解决方案