xpath 解析带<![CDATA[ xml

前端之家收集整理的这篇文章主要介绍了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

猜你在找的XML相关文章