<?xml version="1.0" encoding="utf-8"?>
<_canceled xmlns="http://webservice.hrm.weaver"></_canceled>
<_code/>
<_fullname>水产技术推广服务中心</_fullname>
<_shortname>水产技术推广服务中心</_shortname>
<_showorder/>
<_subcompanyid>2437_0</_subcompanyid>
<_supsubcompanyid>2084_0</_supsubcompanyid>
<_website/>
/ns2:SubCompanyBean
<_canceled xmlns="http://webservice.hrm.weaver"></_canceled>
<_code/>
<_fullname>水产技术推广服务中心</_fullname>
<_shortname>水产技术推广服务中心</_shortname>
<_showorder/>
<_subcompanyid>2437_0</_subcompanyid>
<_supsubcompanyid>2084_0</_supsubcompanyid>
<_website/>
/ns2:SubCompanyBean
这是调用接口返回数组,循环出来的XML。。怎么解析
public class Dom4j
{
private SAXReader reader;
Document document;
String FileName;
public Dom4j(String FileName) throws DocumentException
{
reader = new SAXReader();
document = reader.read(FileName);
this.FileName = FileName;
}
public static void Dom4jParser()
{
Dom4j dom4j;
try
{
dom4j = new Dom4j("src/xml/data.xml"); //这里填你的xml路径
dom4j.getTagbyNameXpath("_canceled", "xmlns");
} catch (DocumentException e)
{
e.printStackTrace();
}
}
private void getTagbyNameXpath(String tag, String att)
{
//查询所有tag
List<Node> list = document.selectNodes("//"+tag);
for(Node n:list)
{
Element e = (Element)n;
String attr = e.attributeValue(att);
if (attr != null)
System.out.println(attr);
}
}
}
它合并了许多超出基本XML文档表示的功能,包括集成的XPath支持,XML Schema支持以及用于大文档或流化文档的基于事件的处理