假设我有这个XML:
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<TopmostSubform>
<!-- more nodes -->
</TopmostSubform>
</xfa:data>
</xfa:datasets>
我想根据文档的路径搜索节点。
"/*/*/*[local-name()='TopmostSubform']"
不能工作吗?
Node dom = getRootDom();
String xpathExpression = "/*/*/*[local-name()='TopmostSubform']";
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expression = xPath.compile(xpathExpression);
Node node = (Node) expression.evaluate(dom, XPathConstants.NODE);
这给了我Node == null
。