dom4j 获取xml中指定节点的信息

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public static void main(String[] args) {
       String xmlString=""
       + ""
        +""
         +"000000" 
          +"N"
          +"认证成功"
        +""
        +""
        +" "
        +"";
       try {
           Document doc = DocumentHelper.parseText(xmlString);
           Element root =doc.getRootElement();
           Element head = root.element("head");
           String  errorTyp =head.element("errorTyp").getTextTrim();
           String  errorCod =head.element("errorCod").getTextTrim();
           String  errorMsg =head.element("errorMsg").getTextTrim();
           if("N".equals(errorTyp) && "000000".equals(errorCod)){
               System.out.println("errorTyp="+errorTyp+",errorCod="+errorCod+",errorMsg="+errorMsg);
           }
       } catch (DocumentException e) {
           e.printStackTrace();
       }
    }

 

你可能感兴趣的:(学习随笔,dom4j)