例如,我想返回一个节点的名称,即一个字符串,因此
/MxML/trade/trade/tradeBody/*1/local-name()
但是,当我尝试用doc.valueOf或doc.selectSingleNode或其他任何方法计算它时,我得到了这个错误:
org.dom4j.InvalidXPathException:无效的XPath表达式:/MxML/trade/tradeBody/*1/local-name()应为节点类型
我知道这意味着什么,我返回的是一个字符串,而不是一个节点,那么我该如何请求这个字符串呢?
谢谢。
发布于 2012-07-08 07:37:21
您确定它可以与JAXP一起工作吗?在我看来,这个表达式并不好;local-name()不是一个节点步骤。
这对dom4j来说很好:
Document doc = DocumentHelper
.parseText("<x:fish xmlns:x='42'>Goodbye, and thanks for all the fish</x:fish>");
XPath xpath = new DefaultXPath("local-name(/*[1])");
Object result = xpath.evaluate(doc);
System.out.printf("Type: %s, Value: %s\n", result.getClass()
.getSimpleName(), result);打印
Type: String, Value: fish
https://stackoverflow.com/questions/11362252
复制相似问题