1、解析String類型的XML字符串得到屬性值
String resultXML = "<?xml version="1.0" encoding="UTF-8"?>
<result>
<message value="0">yongyoulogin|用友ESB測試人員|創建|失敗|人員已存在,</message>
......
/result>";
(1)、得到message中value的值
//解析XML串
StringReader sr = new StringReader(resultXML);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder= factory.newDocumentBuilder();
Document doc = builder.parse(is);
org.w3c.dom.Element root = doc.getDocumentElement();
NodeList nl = root.getChildNodes();
Node message = nl.item(0);
String value = message.getAttributes().getNamedItem("value").getNodeValue();
(2)、得到標簽中間的值
String text = message.gettextcontent(); (text="yongyoulogin|用友ESB測試人員|創建|失敗|人員已存在,")