解析soap Xml

@Test
public void main() {
    String deptXML = "\"1.0\" encoding=\"UTF-8\"?>"
            +"\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:gateway=\"http://www.agree.com.cn/GDBGateway\">"
            +""
            +"\"http://schemas.xmlsoap.org/soap/actor/next\" soapenv:mustUnderstand=\"0\">"
            +"1"
            +""
            +""
            +""
            +""
            +"\"ERR_CODE\">CH0000"
            +"\"ERR_MSG\">查询成功"
            +"\"TOTAL_PAGE_NUM\">1"
            +"\"CURRENT_PAGE_NUM\">1"
            +"\"CURRENT_PAGE_COUNT\">2"

            +"\"TX_DATE\">20170822"
            +"\"TX_TIME\">055606"
            +"\"IN_STAT\">借记卡1"

            +"\"TX_DATE\">20170823"
            +"\"TX_TIME\">055616"
            +"\"IN_STAT\">借记卡2"
            +""
            +""
            +"";
    org.jsoup.nodes.Document doc = Jsoup.parse(deptXML);
    org.jsoup.select.Elements fieldEle = doc.getElementsByTag("gateway:field");
    String code = fieldEle.select("[name=ERR_CODE]").get(0).text();//取状态
    System.out.println("状态码:"+code);
    if(code!=null&&"CH0000".equals(code)){
        //请求成功处理
        int count = Integer.parseInt(fieldEle.select("[name=CURRENT_PAGE_COUNT]").get(0).text());
        //写法1
        for(int i=0;i;i++){
            System.out.println("第"+(i+1)+"个");
            org.jsoup.nodes.Element dateEle = fieldEle.select("[name=TX_DATE]").get(i);
            System.out.println("TX_DATE:"+dateEle.text());
            org.jsoup.nodes.Element timeEle = dateEle.nextElementSibling();
            System.out.println("TX_TIME:"+timeEle.text());
            org.jsoup.nodes.Element statEle = timeEle.nextElementSibling();
            System.out.println("IN_STAT:"+statEle.text());
        }
       System.out.println("-------分割线---------");
        //写法2
        for(int i=0;i;i++){
            System.out.println("第"+(i+1)+"个");
            org.jsoup.nodes.Element dateEle = fieldEle.select("[name=TX_DATE]").get(i);
            System.out.println("TX_DATE:"+dateEle.text());
            org.jsoup.nodes.Element timeEle = fieldEle.select("[name=TX_TIME]").get(i);
            System.out.println("TX_TIME:"+timeEle.text());
            org.jsoup.nodes.Element statEle = fieldEle.select("[name=IN_STAT]").get(i);
            System.out.println("IN_STAT:"+statEle.text());
        }

    }
}

你可能感兴趣的:(2017-08,renshou)