dom4j自己的jar包里面是不包含xpath处理的功能的,你想用xpath的功能,需要一个专门的xpath处理包poi-2.5.1-final-20040804.jar(版本可能不同,名字应该差不多),在你下载的dom4j里面找找,应该能找到的
解决方案 »
- 跪求一片关于J2EE外文翻译(要求原文 +翻译文)
- jsp登录界面 采用Hibernate DAO访问数据库(SQL Server2000)错误不知怎么解决
- java串口编程
- 【50分求助】swing图形设计
- 请问用JBOSS中的jboss-j2ee.jar包里面怎么缺少Stateless呢?
- 像天猫那种选择商品,有很多筛选的条件,我翻页的时候怎么记住那些条件,翻页的时候基于这些条件来翻页的
- 请大家说说哪一种开源的消息中间件比较好啊?
- java 调用存储过程的问题?急啊,在线等待..............
- 什么方法可以定时重启tomcat?
- 用过WSAD开发过带模块Struts的快过来,快快救命啊
- 关于struts的<logic:iterator>的问题
- JDBC-ODBC问题
if(pFileName==null||pFileName.equals("")) return null;
return getDocument(new File(pFileName));
} public static Document getDocument(File pFile) {
if(pFile==null || !pFile.exists()) return null;
try {
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
if(dbf==null) return null;
DocumentBuilder df=dbf.newDocumentBuilder();
if(df==null) return null;
return df.parse(pFile);
}
catch (Exception any) {
logger.error(any);
return null;
}
}
try{
Document doc=getDocument("the file.xml");
String xpath="//main/books"; Node node = XPathAPI.selectSingleNode(doc, xpath);
if(node!=null){
Element _node=doc.create.....Element("book");
_node......set //or add Text
node.add....Element or Node( _node);
}
//to save the document;
}catch(Exception any){
logger.error(any);
}
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.apache.xpath.XPathAPI;
运行后test.xml的内容为
<?xml version="1.0" encoding="GBK"?><main>
<books>
<book>mybook</book>
</books>
</main>你看一下是不是你DOM4j的版本问题,我用的是1.4的.