import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public static void main(String[] args) {
String xmlString="<?xml version=\"1.0\" encoding=\"GBK\"?>"
+ "<root>"
+"<head>"
+"<errorCod>000000</errorCod>"
+"<errorTyp>N</errorTyp>"
+"<errorMsg>认证成功</errorMsg>"
+"</head>"
+"<body>"
+"</body> "
+"</root>";
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();
}
}