/**
* Get values matching passed XPath expression
* @param node
* @param expression XPath expression
* @return matching values
* @throws Exception
*/
private static String[] getByXpath( Node node, String expression ) throws Exception {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
XPathExpression xPathExpression = xPath.compile(expression);
NodeList nlist = (NodeList) xPathExpression.evaluate(node, XPathConstants.NODESET);
int nodeListSize = nlist.getLength();
List<String> values = new ArrayList<String>(nodeListSize);
for (int index = 0; index < nlist.getLength(); index++) {
Node aNode = nlist.item(index);
values.add(aNode.getTextContent());
}
return values.toArray(new String[values.size()]);
}
XmlUtilities.java 文件源码
java
阅读 17
收藏 0
点赞 0
评论 0
项目:ats-framework
作者:
评论列表
文章目录