Helper program: Extracts the specified XPATH expression
from an XML-String.

@param node  the node
@param xPath the x path
@return NodeList
@throws XPathExpressionException the x path expression exception
195512
public static Node getElementB(Node node, String xPath) throws XPathExpressionException {
        XPathExpression expr = xpath.compile(xPath);
        return getElementB(node, expr);
    }
800890
public T xpath(String expression, String value) {
        if (xpathMessageConstructionInterceptor == null) {
            xpathMessageConstructionInterceptor = new XpathMessageConstructionInterceptor();

            if (getAction().getMessageBuilder() != null) {
                (getAction().getMessageBuilder()).add(xpathMessageConstructionInterceptor);
            } else {
                PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
                messageBuilder.getMessageInterceptors().add(xpathMessageConstructionInterceptor);

                getAction().setMessageBuilder(messageBuilder);
            }
        }

        xpathMessageConstructionInterceptor.getXPathExpressions().put(expression, value);
        return self;
    }
14311
public static Object executeXPath(Node document, XPathExpression expr, QName result) throws XPathException, MarshallingException
    {
        try
        {
            return expr.evaluate(document, result);
        }
        catch (Exception e)
        {
            throw new MarshallingException("Exception unmarshalling XML.", e);
        }
    }
1248927
public static String evaluate(String xpath, String html) throws XPathExpressionException,
            ParserConfigurationException {
        HtmlCleaner hc = new HtmlCleaner();
        TagNode tn = hc.clean(html);
        Document document = new DomSerializer(new CleanerProperties()).createDOM(tn);
        XPath xPath = XPathFactory.newInstance().newXPath();
        return xPath.evaluate(xpath, document);
    }
818358
public String execute( String xPath ) throws Exception {

		if ( xPath == null ){
			return null;
		}
		
		// Evaluate the xpath expression
		return XPathAPI.eval( getDoc(), xPath ).toString();
		
	
	}
776359
public Node getNode(String expression) {
		return (Node) evalXPath(expression, null, XPathConstants.NODE);
	}
303404
public String verifyXPathExpression(final Iterable<XmlNsScheme> xmlNsSchemes, final String xpathExpression)
    {
        LOG.trace("verifyXPathExpression: {}", xpathExpression);
        final XPathCompiler xPathCompiler = processor.newXPathCompiler();
        for (final XmlNsScheme xmlNsScheme : xmlNsSchemes)
        {
            final String localPart = xmlNsScheme.getQName().getLocalPart();
            final String namespaceUri = xmlNsScheme.getQName().getNamespaceURI();
            LOG.trace("declareNamespace {}:{}", localPart, namespaceUri);
            xPathCompiler.declareNamespace(localPart, namespaceUri);
        }
        try
        {
            xPathCompiler.compile(xpathExpression);
        }
        catch (final SaxonApiException e)
        {
            return e.getCause().getMessage();
        }
        return "";
    }
1343568
public static NodeList applyXpathExpressionToDocument(String _xpathExpression, Node _xmlDocumentOrNode)
            throws IOException {

        XPathFactory xfactory = XPathFactory.newInstance();
        XPath xpath = xfactory.newXPath();
        XPathExpression expr = null;
        try {
            expr = xpath.compile(_xpathExpression);
        } catch (XPathExpressionException _ex) {
            throw new IOException(_ex);
        }

        Object result = null;
        try {
            result = expr.evaluate(_xmlDocumentOrNode, XPathConstants.NODESET);
        } catch (Exception _ex) {
            throw new IOException(_ex);
        }

        return (NodeList) result;
    }
1005807
public final java.util.List<String> expressionList() throws RecognitionException {
		java.util.List<String> exprs = null;


		ParserRuleReturnScope f =null;
		ParserRuleReturnScope s =null;

		 exprs = new java.util.ArrayList<String>();
		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:680:3: (f= expression ( COMMA s= expression )* )
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:680:7: f= expression ( COMMA s= expression )*
			{
			pushFollow(FOLLOW_expression_in_expressionList4122);
			f=expression();
			state._fsp--;
			if (state.failed) return exprs;
			if ( state.backtracking==0 ) { exprs.add( (f!=null?input.toString(f.start,f.stop):null) ); }
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:681:7: ( COMMA s= expression )*
			loop88:
			while (true) {
				int alt88=2;
				int LA88_0 = input.LA(1);
				if ( (LA88_0==COMMA) ) {
					alt88=1;
				}

				switch (alt88) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:681:8: COMMA s= expression
					{
					match(input,COMMA,FOLLOW_COMMA_in_expressionList4133); if (state.failed) return exprs;
					pushFollow(FOLLOW_expression_in_expressionList4137);
					s=expression();
					state._fsp--;
					if (state.failed) return exprs;
					if ( state.backtracking==0 ) { exprs.add( (s!=null?input.toString(s.start,s.stop):null) ); }
					}
					break;

				default :
					break loop88;
				}
			}

			}

		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
		}
		return exprs;
	}
937396
public static XElements select(Element element, String xpathStr) {
        return XPathParser.parse(xpathStr).evaluate(element);
    }
1344431
public static Date asDate(String expression, Node node, XPath xpath)
            throws XPathExpressionException {
        String dateString = evaluateAsString(expression, node, xpath);
        if (isEmptyString(dateString)) return null;

        try {
            return DateUtils.parseISO8601Date(dateString);
        } catch (Exception e) {
            log.warn("Unable to parse date '" + dateString + "':  " + e.getMessage(), e);
            return null;
        }
    }
754784
@SuppressWarnings("rawtypes")
	public List<NodeConfig> parserByXpath(InputStreamReader xml, String xpath) throws UnmarshalException {
		
		List<NodeConfig> nodeConfigList = new ArrayList<NodeConfig>();
		SAXBuilder builder = new SAXBuilder(false);
		Document doc = null;
		
		try {
			doc = builder.build(xml);
			Element root = doc.getRootElement();
			
			if (xpath != null && !xpath.equals("")) {
				List selectNodes = XPath.selectNodes(root, xpath);
				for (Iterator iterNode = selectNodes.iterator(); iterNode.hasNext();) {
					NodeConfig nodeConfig = parserNode((Element) iterNode.next());
					nodeConfigList.add(nodeConfig);
				}
			}
			
			return nodeConfigList;
		} catch (JDOMException e) {
			throw new UnmarshalException(e);
		} catch (IOException e) {
			throw new UnmarshalException(e);
		}

	}
1269752
public @Nonnull Stream<XQuery> select(String xpath) {
        return new NodeListSpliterator(evaluate(xpath)).stream().map(XQuery::new);
    }
183466
public static void assertXpathEvaluatesTo(QualifiedName expectedValue,
                                              String xpathExpression,
                                              Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        NodeList nl =
            simpleXpathEngine.getMatchingNodes(xpathExpression, inDocument);
        NamespaceContext ctx = null;
        if (nl.getLength() > 0) {
            ctx = new NodeBasedNamespaceContext(nl.item(0));
        }
        assertEquals(expectedValue,
                     QualifiedName
                     .valueOf(simpleXpathEngine.evaluate(xpathExpression,
                                                         inDocument),
                              ctx));
    }
699247
public static NodeList evaluateXpathExpression(String domStr, String xpathExpr)
			throws XPathExpressionException, IOException {
		Document dom = DomUtils.asDocument(domStr);
		return evaluateXpathExpression(dom, xpathExpr);
	}
1250565
private AbstractExpression parseExpressionNode(VoltXMLElement exprNode) {
        String elementName = exprNode.name.toLowerCase();

        XMLElementExpressionParser parser = m_exprParsers.get(elementName);
        if (parser == null) {
            throw new PlanningErrorException("Unsupported expression node '" + elementName + "'");
        }
        AbstractExpression retval = parser.parse(this, exprNode);
        assert("asterisk".equals(elementName) || retval != null);
        return retval;
    }
255440
public static Object evaluate(Node node, String xPathExpression,
            NamespaceContext nsContext, XPathExpressionResult resultType) {
        if (resultType.equals(XPathExpressionResult.NODE)) {
            Node resultNode = evaluateAsNode(node, xPathExpression, nsContext);

            if (resultNode.getNodeType() == Node.ELEMENT_NODE) {
                if (resultNode.getFirstChild() != null) {
                    return resultNode.getFirstChild().getNodeValue();
                } else {
                    return "";
                }
            } else {
                return resultNode.getNodeValue();
            }
        } else if (resultType.equals(XPathExpressionResult.NODESET)) {
            NodeList resultNodeList = evaluateAsNodeList(node, xPathExpression, nsContext);

            List<String> values = new ArrayList<>();
            for (int i = 0; i < resultNodeList.getLength(); i++) {
                Node resultNode = resultNodeList.item(i);

                if (resultNode.getNodeType() == Node.ELEMENT_NODE) {
                    if (resultNode.getFirstChild() != null) {
                        values.add(resultNode.getFirstChild().getNodeValue());
                    } else {
                        values.add("");
                    }
                } else {
                    values.add(resultNode.getNodeValue());
                }
            }

            return values;
        } else if (resultType.equals(XPathExpressionResult.STRING)) {
            return evaluateAsString(node, xPathExpression, nsContext);
        } else {
            Object result = evaluateAsObject(node, xPathExpression, nsContext, resultType.getAsQName());

            if (result == null) {
                throw new CitrusRuntimeException("No result for XPath expression: '" + xPathExpression + "'");
            }

            if (resultType.equals(XPathExpressionResult.INTEGER)) {
                return (int) Math.round((Double) result);
            }

            return result;
        }
    }