标签:att 解析xml message ext 字符 解析 extc attr 测试
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测试人员|创建|失败|人员已存在,")
标签:att 解析xml message ext 字符 解析 extc attr 测试
原文地址:http://www.cnblogs.com/fengzhanfei/p/6136901.html