DocumentHelper解析xml⽂件
public class TestXml2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String transMessage = "<?xml version=\"1.0\" encoding=\"GBK\"?><message>" + "<body>" + "<ticketNotify>"
+ "<ticket id=\"6000012007051000000231\" dealTime=\"20070510165423\" status=\"0000\" message=\"成功,系统处理正常\"/>"
+ "<ticket id=\"6000012007051000000232\" dealTime=\"20070510165424\" status=\"2012\" message=\"禁⽌倍投\"/>"
使用dom4j解析xml文件+ "</ticketNotify>" + "</body></message>";
try {
Document document=DocumentHelper.parseText(transMessage);
Element RootElement();
Iterator iterator=root.element("body").element("ticketNotify").elementIterator();
while(iterator.hasNext()) {
Element element=(Element) ();
System.out.print(element.attributeValue("id")+" ");
System.out.print(element.attributeValue("dealTime")+" ");
System.out.println(element.attributeValue("status")+" ");
}
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<!-- mvnrepository/artifact/dom4j/dom4j -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。