List of utility methods to do XPath Create
String | getXPathExpression(final Node node) Returns the unique XPath expression for the given node. String xpathExpression = node.getNodeName(); if (node.getParentNode() != null) { int index = 0; Node prec = node; while (prec != null) { if (prec.getNodeName().equals(node.getNodeName())) { index++; prec = prec.getPreviousSibling(); if (node.getParentNode() instanceof Document) { ; } else { xpathExpression = getXPathExpression(node.getParentNode()) + "/" + xpathExpression + "[" + String.valueOf(index) + "]"; return xpathExpression; |
XPathExpression | getXPathExpression(String expression) get X Path Expression return getXPath().compile(expression);
|
XPathExpression | getXPathExpression(String path) get X Path Expression path = path.trim(); try { XPath xp = XPathFactory.newInstance().newXPath(); XPathExpression expr = xp.compile(path); return expr; } catch (Exception ex) { throw new RuntimeException(ex); |
XPathExpression | getXPathExpression(String xpath, NamespaceContext namespaceContext) get X Path Expression return createXPathExpression(xpath, namespaceContext);
|
XPathExpression | getXPathExpression(String xpathStr) Get xpath expression object by xpath string return XPathFactory.newInstance().newXPath().compile(xpathStr);
|
XPathExpression | getXPathExpression(String xPathString) get X Path Expression SoftReference<XPathExpression> ref = xPathExpressionsCache.get(xPathString); XPathExpression expression = ref == null ? null : ref.get(); if (expression == null) xPathExpressionsCache.put(xPathString, new SoftReference<XPathExpression>(expression = getSharedXPath().compile(xPathString))); return expression; |
Node | getXpathExpressionNode(Object xprContext, String xpExpression) get Xpath Expression Node XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression xpe = xpath.compile(xpExpression);
Node node = (Node) xpe.evaluate(xprContext, XPathConstants.NODE);
return node;
|
String | getXpathExpressionValue(Object xprContext, String xpExpression) get Xpath Expression Value XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpe = xpath.compile(xpExpression); Node valueNode = (Node) xpe.evaluate(xprContext, XPathConstants.NODE); String value = null; if (valueNode != null) value = valueNode.getNodeValue(); if (value != null) { if (valueNode.getNodeType() == Node.TEXT_NODE) { ... |
String | getXPathExprFromNode(Node node) Generates an XPath expression that will return only the given node as its result. short nodeType = getNodeType(node); switch (nodeType) { case Node.ELEMENT_NODE: case Node.TEXT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: return getXPathFromVector(getVectorPathFromNode(node)); case Node.DOCUMENT_NODE: return "/"; ... |
String | getXPathExprFromNode(Node node) Generates an XPath expression that will return only the given node as its result. short nodeType = getNodeType(node); switch (nodeType) { case Node.ELEMENT_NODE: case Node.TEXT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: return getXPathFromVector(getVectorPathFromNode(node)); case Node.DOCUMENT_NODE: return "/"; ... |