Java Code Examples for org.apache.xpath.XPathContext#getDTMHandleFromNode()
The following examples show how to use
org.apache.xpath.XPathContext#getDTMHandleFromNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPathHelper.java From htmlunit with Apache License 2.0 | 6 votes |
/** * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string * @param a prefix resolver to use for resolving namespace prefixes, or null * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be {@code null}) * @throws TransformerException if a syntax or other error occurs */ private static XObject evaluateXPath(final DomNode contextNode, final String str, final PrefixResolver prefixResolver) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { xpathExpressionContext = ((Document) contextNode).getDocumentElement(); } else { xpathExpressionContext = contextNode; } PrefixResolver resolver = prefixResolver; if (resolver == null) { resolver = new HtmlUnitPrefixResolver(xpathExpressionContext); } final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); final XPathAdapter xpath = new XPathAdapter(str, null, resolver, null, caseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
Example 2
Source File: XPathUtils.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string * @param a prefix resolver to use for resolving namespace prefixes, or null * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be {@code null}) * @throws TransformerException if a syntax or other error occurs */ private static XObject evaluateXPath(final DomNode contextNode, final String str, final PrefixResolver prefixResolver) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { xpathExpressionContext = ((Document) contextNode).getDocumentElement(); } else { xpathExpressionContext = contextNode; } PrefixResolver resolver = prefixResolver; if (resolver == null) { resolver = new HtmlUnitPrefixResolver(xpathExpressionContext); } final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); final boolean attributeCaseSensitive = caseSensitive || contextNode.getPage().getWebClient() .getBrowserVersion().hasFeature(XPATH_ATTRIBUTE_CASE_SENSITIVE); final XPathAdapter xpath = new XPathAdapter(str, null, resolver, null, caseSensitive, attributeCaseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }