1、解析String类型的XML字符串得到属性值
String resultXML = "<?xml version="1.0" encoding="UTF-8"?>
yongyoulogin|用友ESB测试人员|创建|失败|人员已存在,
…
/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测试人员|创建|失败|人员已存在,”)