微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xpath 解析带<![CDATA[ xml

book.xml


<?xml version="1.0" encoding="utf-8"?>
<config>
  <cooperator code="bsg">
    <comefrom code="bsg002">
      <ip>
      </ip>
      <key><![CDATA[Tc7ib084USQ5LCEmaaBUlNdlxSLvWQlcEepFWdcV8Ac44RFShWxNXhBexKkhDn8g]]></key>
      <synccallback>http://xxx/return.jsp</synccallback>
      <timeinterval>30</timeinterval>
    </comefrom>
  </cooperator>
</config>


java

import java.io.FileInputStream;  
import java.io.IOException;  
import java.io.InputStream;  
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
public class MyDomParse {
	public static void main(String args[]) 
	{ 
	try { 
	InputStream x=new FileInputStream("d:/book.xml");
	org.dom4j.io.SAXReader saxReader = new SAXReader();
	Document doc = saxReader.read(x);
	String xpath ="/config/cooperator/comefrom/key";
	System.out.print(doc.selectSingleNode(xpath).getText());  
	} catch (IOException e) { 
	// Todo Auto-generated catch block 
	e.printstacktrace(); 
	} catch (DocumentException e) {
		// Todo Auto-generated catch block
		e.printstacktrace();
	}  
	}  
}
需要 dom4j.jar,jaxen-1.1.2.jar

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。