JAVA parses XML files

   String head="<?xml version=\"1.0\" encoding=\"GB2312\"?> \n;

   String content="<alipay>

                        <success>T</success>

                        <response>

                        <order>

                        <batch_status>P</batch_status> <btn_num>ff</btn_num>

                        </order> 

                        </response>  

                        </alipay> ";

try{

        XML xml=XML.readFrom(head+content);

        Element e1=xml.getRoot();//What gets is alipay

        Element e2=e1.getChild("response");

        Element e3=e2.getChild("order");

        if (e3.getChild("batch_status") !=null && !"".equals(e3.getChild(batch_status)){

             Element batch_status=e3.getChild("batch_status");

                         String str=batch_status.getText();

        }

     //Each Element needs to be judged by if, otherwise a null pointer exception will be reported

 }catch(Exception e){


}finally{


}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938593&siteId=291194637