我有一个节点,它是 XPath 选择的结果。我可以检查这个节点是否是一个属性吗?
代码示例:
Document doc = builder.parse(new StringInputStream(xml));
XPathExpression expression = xpath.compile(path);
DTMNodeList result = (DTMNodeList) expression.evaluate(doc, XPathConstants.NODESET);
Node node = result.item(0);//how to check if this node is an attribute
示例 XML:
<a atr='asdf'></a>
路径:
/a/@atr