解析xml

 // 进行对books.xml文件的JDOM解析
            // 准备工作
            // 1.创建一个SAXBuilder的对象
            try {
                String fileName=IOSDesUtil.decode(nt_data,"16227770222562152215652237257219");
                Log.d(" 执行2 fileName"+fileName);
                // 2.创建一个输入流,将xml文件加载到输入流中
                Element rootElement  = DocumentHelper.parseText(fileName).getRootElement();
                Log.d(" 执行2 rootElement"+rootElement);
                // 2.创建一个输入流,将xml文件加载到输入流中
//            in = new ByteArrayInputStream(fileName.getBytes());
//            SAXReader reader = new SAXReader();
//            Document read = reader.read(in);
//            Element rootElement = read.getRootElement();
                Iterator it = rootElement.elementIterator();
                // 遍历迭代器,获取根节点中的信息(书籍)
                //  Node node = rootElement.selectSingleNode("quicksdk_message");
                while (it.hasNext()) {
                    System.out.println("=====开始遍历某一本书=====");
                    Element book = (Element) it.next();
                    // 获取book的属性名以及 属性值
                    List bookAttrs = book.attributes();
                    for (Attribute attr : bookAttrs) {
                        System.out.println("属性名:" + attr.getName() + "--属性值:"
                                + attr.getValue());
                    }
                    Iterator itt = book.elementIterator();
                    while (itt.hasNext()) {
                        Element bookChild = (Element) itt.next();
                        if ("is_test".equals(bookChild.getName() )){
                            is_test=bookChild.getStringValue();
                          //  System.out.println("节点名:" + bookChild.getName() + "--节点值:" + bookChild.getStringValue());
                        } if ("channel".equals(bookChild.getName() )){
                            channel=bookChild.getStringValue();
                         //   System.out.println("节点名:" + bookChild.getName() + "--节点值:" + bookChild.getStringValue());
                        } if ("channel_uid".equals(bookChild.getName() )){
                            channel_uid=bookChild.getStringValue();
                        //    System.out.println("节点名:" + bookChild.getName() + "--节点值:" + bookChild.getStringValue());
                        } if ("game_order".equals(bookChild.getName() )){
                            game_order=bookChild.getStringValue();
                        } if ("order_no".equals(bookChild.getName() )){
                            order_no=bookChild.getStringValue();
                        } if ("pay_time".equals(bookChild.getName() )){
                            pay_time=bookChild.getStringValue();
                        } if ("amount".equals(bookChild.getName() )){
                            amount=bookChild.getStringValue();
                        } if ("status".equals(bookChild.getName() )){
                            status=bookChild.getStringValue();
                        }
                        if ("extras_params".equals(bookChild.getName() )){
                            extras_params=bookChild.getStringValue();
                            break;
                        }
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

你可能感兴趣的:(遇到的问题)