Document document = null;
//xmlString is the data in xml format of String type
String xmlString="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<root>"
+"<data ret_code=\"0\" error_message=\"失败原因\">"
+"<refund_no>That's it</refund_no>"
+"</data>"
+"<sign>xxxxxxxxxxxxxxxxxxx</sign>"
+"</root>";
document = DocumentHelper.parseText(xmlString);
System.out.println("document"+document);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
//Get the root node element object
Element root = document.getRootElement();
// get child nodes
System.out.println("Name of current node: " + root .getName());
//
Element data = root .element("data"); //Get child node
String ret_code= data.attributeValue("ret_code");//Get the value of the child node attribute
String error_message= data.attributeValue("error_message");//Get the value of the child node attribute
System.out.println("ret_code:" +ret_code+"error_message:"+error_message);
String text= data.elementText("refund_no");//Get the value of the node
Stringsign= node.elementText("sign");Get the text of the node
System.out.println(text+sign+">>>");