• android XML解析


    public void Userinfo() {
            String str = flag;
            DataCenter d = new DataCenter(con);
            ByteArrayInputStream bInputStringStream = null;
            try {
                if (str != null && !str.trim().equals("")) {
                    bInputStringStream = new ByteArrayInputStream(str.getBytes());
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
            try {
                XmlPullParser xmlparser = Xml.newPullParser();
    
                xmlparser.setInput(bInputStringStream, "UTF-8");
                int eventType = xmlparser.getEventType();
                String[] User_info = new String[21];
    
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
                        d.open();
                        break;
                    case XmlPullParser.START_TAG:// 开始元素事件
                        String name = xmlparser.getName();// 字段名
                        if (name.equalsIgnoreCase("uid")) {
                            User_info[0] = xmlparser.nextText();
                        } else if (name.equalsIgnoreCase("psw")) {
                            User_info[1] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("name")) {
                            User_info[2] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("major")) {
                            User_info[3] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("department")) {
                            User_info[4] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("email")) {
                            User_info[5] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("unit")) {
                            User_info[6] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("tel")) {
                            User_info[7] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("mobile")) {
                            User_info[8] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("postcode")) {
                            User_info[9] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("address")) {
                            User_info[10] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("homepage")) {
                            User_info[11] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("regTime")) {
                            User_info[12] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("lastTime")) {
                            User_info[13] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("priv")) {
                            User_info[14] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("bxlx")) {
                            User_info[15] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("xxtz")) {
                            User_info[16] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("orderId")) {
                            User_info[17] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("deviceTotal")) {
                            User_info[18] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("deviceArea")) {
                            User_info[19] = xmlparser.nextText();
    
                        } else if (name.equalsIgnoreCase("cjType")) {
                            User_info[20] = xmlparser.nextText();
                        }
                        break;
                    case XmlPullParser.END_TAG:// 结束元素事件
    
                        break;
                    }
                    eventType = xmlparser.next();
                }
                d.insertUser(User_info);
                bInputStringStream.close();
                d.close();
            } catch (XmlPullParserException e) {
                // TODO Auto-generated catch block
                flag = null;
                e.printStackTrace();
    
            } catch (IOException e) {
                // TODO Auto-generated catch block
                flag = null;
                e.printStackTrace();
            }
            flag = null;
        }
  • 相关阅读:
    【Vue】 修饰符sync
    【VUE】vue路由跳转的方式
    【Element】elementui的Cascader 级联选择器,在懒加载的时候数据无法回显的解决方案
    【ES6】利用ES6 Set 将数组去重
    【.NETCORE】Refit 框架
    【.NETCORE】ASP.NET Core SignalR
    【Visual Studio Code】驼峰翻译助手
    VueX(Vue状态管理模式)
    hdmi 随笔
    ad 差分布线 等长布线
  • 原文地址:https://www.cnblogs.com/wuyihong/p/2569935.html
Copyright © 2020-2023  润新知