日期:2014-05-20  浏览次数:20715 次

用xpath获取xml中的子节点问题
Xml代码  
<?xml version="1.0" encoding="utf-8"?>  
<ROOT>  
<APP_SYSTEM_ID>1000001</APP_SYSTEM_ID >  
<APP_SYSTEM>iteye</APP_SYSTEM >  
<ORGAN operatparam="add">  
  
  
<ORGAN_INFO>  
<ORGAN_ID>101</ORGAN_ID >  
<PARENT_ID>1</PARENT_ID >  
<ORGANNAME>湖南</ORGANNAME >  
<IS_LEAF>02</IS_LEAF >  
<ACCOUNT_ID> </ACCOUNT_ID >  
<PASSWORD> </PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>1</ORGAN_ID >  
<PARENT_ID>-1</PARENT_ID >  
<ORGANNAME>中国</ORGANNAME >  
<IS_LEAF>02</IS_LEAF >  
<ACCOUNT_ID> </ACCOUNT_ID >  
<PASSWORD> </PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>10101</ORGAN_ID >  
<PARENT_ID>101</PARENT_ID >  
<ORGANNAME>长沙市</ORGANNAME >  
<IS_LEAF>02</IS_LEAF >  
<ACCOUNT_ID> </ACCOUNT_ID >  
<PASSWORD> </PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>1010101</ORGAN_ID >  
<PARENT_ID>10101</PARENT_ID >  
<ORGANNAME>烟草局</ORGANNAME >  
<IS_LEAF>02</IS_LEAF >  
<ACCOUNT_ID> </ACCOUNT_ID >  
<PASSWORD> </PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>1010102</ORGAN_ID >  
<PARENT_ID>10101</PARENT_ID >  
<ORGANNAME>农业局</ORGANNAME >  
<IS_LEAF>02</IS_LEAF >  
<ACCOUNT_ID> </ACCOUNT_ID >  
<PASSWORD> </PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>1010101001</ORGAN_ID >  
<PARENT_ID>1010102</PARENT_ID >  
<ORGANNAME>李四</ORGANNAME >  
<IS_LEAF>01</IS_LEAF >  
<ACCOUNT_ID>lisi</ACCOUNT_ID >  
<PASSWORD>lisi</PASSWORD >  
</ORGAN_INFO >  
  
<ORGAN_INFO>  
<ORGAN_ID>1010101001</ORGAN_ID >  
<PARENT_ID>1010101</PARENT_ID >  
<ORGANNAME>李四</ORGANNAME >  
<IS_LEAF>01</IS_LEAF >  
<ACCOUNT_ID>lisi</ACCOUNT_ID >  
<PASSWORD>lisi</PASSWORD >  
</ORGAN_INFO >  
  
</ORGAN >  
  
  
</ROOT >  
 上面是我的xml文件内容。
 
Java代码  
public class XmlParseHelper {  
  private DocumentBuilder builder;  
  private Document document;  
  private Element root;  
  
  public XmlParseHelper(InputStream is) throws IOException {  
  
  this.document = null;  
  this.builder = null;  
  
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
  factory.setNamespaceAware(false);  
  try {  
  this.builder = factory.newDocumentBuilder();  
  
  this.builder.setEntityResolver(new EntityResolver() {