我知道类似的问题已得到解答,但它们并没有完全解决我的具体问题:
public String getValue(String xPath) {
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new PersonalNamespaceContext());
String value = null;
NodeList nodes = null;
try {
XPathExpression expr = xpath.compile(xPath);
nodes = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
System.out.println("nodes: " + nodes.getLength());
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int idx = 0; idx < nodes.getLength(); idx++) {
value = nodes.item(idx).getTextContent();
System.out.println(value);
//break;
}
return value;
}
我需要能够获得“可见”文本节点的值。
<itemlocation>
<x>0</x>
<y>0</y>
</itemlocation>
<visible>off</visible>
</pane>
我似乎无法找到正确的xPath值来执行此操作。有没有人有任何想法?