book.xml
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 原文链接:https://www.f2er.com/xml/299892.html