/** * Evaluate XPath string to an XObject. Using this method, * XPath namespace prefixes will be resolved from the namespaceNode. * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see org.apache.xpath.objects.XObject * @see org.apache.xpath.objects.XNull * @see org.apache.xpath.objects.XBoolean * @see org.apache.xpath.objects.XNumber * @see org.apache.xpath.objects.XString * @see org.apache.xpath.objects.XRTreeFrag * * @throws TransformerException */ public XObject eval(Node contextNode, String str) throws TransformerException { return eval(contextNode, str, contextNode); }
/** * Evaluate XPath string to an XObject. Using this method, * XPath namespace prefixes will be resolved from the namespaceNode. * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see org.apache.xpath.objects.XObject * @see org.apache.xpath.objects.XNull * @see org.apache.xpath.objects.XBoolean * @see org.apache.xpath.objects.XNumber * @see org.apache.xpath.objects.XString * @see org.apache.xpath.objects.XRTreeFrag * * @throws TransformerException */ public XObject eval(Node contextNode, String str) throws TransformerException { return eval(contextNode, str, contextNode); }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public NodeIterator selectNodeIterator( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Have the XObject return its result as a NodeSetDTM. return list.nodeset(); }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public NodeList selectNodeList( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Return a NodeList. return list.nodelist(); }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public NodeIterator selectNodeIterator( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Have the XObject return its result as a NodeSetDTM. return list.nodeset(); }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public NodeList selectNodeList( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Return a NodeList. return list.nodelist(); }
protected boolean evaluate(InputSource inputSource) { try { DocumentBuilder dbuilder = createDocumentBuilder(); Document doc = dbuilder.parse(inputSource); //An XPath expression could return a true or false value instead of a node. //eval() is a better way to determine the boolean value of the exp. //For compliance with legacy behavior where selecting an empty node returns true, //selectNodeIterator is attempted in case of a failure. CachedXPathAPI cachedXPathAPI = new CachedXPathAPI(); XObject result = cachedXPathAPI.eval(doc, xpath); if (result.bool()) return true; else { NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath); return (iterator.nextNode() != null); } } catch (Throwable e) { return false; } }
XObject xo = cachedXPathAPI.eval(doc, xpath, getNamespaceContext());
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
protected Object evaluateExpression(Node source, String expression) { try { return xpath.eval(source, expression); } catch (TransformerException transformerException) { throw wrapException(transformerException); } }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public NodeList selectNodeList( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Return a NodeList. return list.nodelist(); }
protected NodeList getNodeList(final Document doc, final String xpath) throws TransformerException { final DefaultPrefixResolver prefixResolver = new DefaultPrefixResolver(doc.getNodeType() == Node.DOCUMENT_NODE ? doc.getDocumentElement() : doc); return getXPathAPI().eval(doc, xpath, prefixResolver).nodelist(); }
protected NodeList getNodeList(final Document doc, final String xpath) throws TransformerException { final DefaultPrefixResolver prefixResolver = new DefaultPrefixResolver( doc.getNodeType() == Node.DOCUMENT_NODE ? doc .getDocumentElement() : doc); return getXPathAPI().eval(doc, xpath, prefixResolver).nodelist(); }
protected NodeList getNodeList(final Document doc, final String xpath) throws TransformerException { final DefaultPrefixResolver prefixResolver = new DefaultPrefixResolver(doc.getNodeType() == Node.DOCUMENT_NODE ? doc.getDocumentElement() : doc); return getXPathAPI().eval(doc, xpath, prefixResolver).nodelist(); }
protected NodeList getNodeList(final Document doc, final String xpath) throws TransformerException { final DefaultPrefixResolver prefixResolver = new DefaultPrefixResolver( doc.getNodeType() == Node.DOCUMENT_NODE ? doc .getDocumentElement() : doc); return getXPathAPI().eval(doc, xpath, prefixResolver).nodelist(); }
protected boolean evaluate(InputSource inputSource) { try { DocumentBuilder dbuilder = createDocumentBuilder(); Document doc = dbuilder.parse(inputSource); //An XPath expression could return a true or false value instead of a node. //eval() is a better way to determine the boolean value of the exp. //For compliance with legacy behavior where selecting an empty node returns true, //selectNodeIterator is attempted in case of a failure. CachedXPathAPI cachedXPathAPI = new CachedXPathAPI(); XObject result = cachedXPathAPI.eval(doc, xpath); if (result.bool()) return true; else { NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath); return (iterator.nextNode() != null); } } catch (Throwable e) { return false; } }