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
776476
public static Node getElementB(Node node, XPathExpression xPath) throws XPathExpressionException {
        return getElementsB(node, xPath).item(0);
    }
131783
public static Node selectNode(Node dom, String xpath) {
        return selector.selectNode(dom, xpath);
    }
808144
public Node getNode(Object node, String expression) {
		return (Node) evalXPath(expression, node, XPathConstants.NODE);
	}
491964
public String getString(Object node, String expression) {
		return (String) evalXPath(expression, node, XPathConstants.STRING);
	}
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;
    }
1275308
public T remove(final CharSequence xpath) {
        if ((xpath == null) || (xpath.length() == 0)) {
            throw new IllegalArgumentException("Parameter path must not be empty or null");
        }
        domChangeTracker.refreshForReadIfNeeded();

        final Document document = DOMHelper.getOwnerDocumentFor(baseNode);
        final DuplexExpression duplexExpression = new DuplexXPathParser(invocationContext.getProjector().config().getUserDefinedNamespaceMapping()).compile(xpath);
        try {
            final XPathExpression expression = invocationContext.getProjector().config().createXPath(document).compile(duplexExpression.getExpressionAsStringWithoutFormatPatterns());
            Node prevNode = (Node) expression.evaluate(boundNode, XPathConstants.NODE);
            if (prevNode == null) {
                return null;
            }
            final T value = DefaultXPathEvaluator.convertToComponentType(invocationContext, prevNode, invocationContext.getTargetComponentType());
            duplexExpression.deleteAllMatchingChildren(prevNode.getParentNode());
            return value;
        } catch (XPathExpressionException e) {
            throw new XBPathException(e, xpath);
        }
    }
216872
public static Object evaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType) {
        try {
            return buildExpression(xPathExpression, nsContext).evaluate(node, returnType);
        } catch (XPathExpressionException e) {
            throw new CitrusRuntimeException("Can not evaluate xpath expression '" + xPathExpression + "'", e);
        }
    }
300763
@Override
    public List<Node> parse(String xml) throws ParseException {
        try {
            final SAXParserFactory factory = SAXParserFactory.newInstance();
            final SAXParser saxParser = factory.newSAXParser();
            final NodeXmlHandler handler = new NodeXmlHandler();

            saxParser.parse(new CharSequenceInputStream(xml, Charset.defaultCharset()), handler);

            return handler.getNodes();
        } catch (IOException ioe) {
            throw new ParseException(ioe);
        } catch (SAXException e) {
            throw new ParseException(e);
        } catch (ParserConfigurationException e) {
            throw new ParseException(e);
        }
    }
1373802
public static Node getNodeByXPath(String expression, Object source) {
		return (Node) getByXPath(expression, source, XPathConstants.NODE);
	}
897276
public static NodeList getElementsB(Node node, XPathExpression xPath)
            throws XPathExpressionException {
        return (NodeList) xPath.evaluate(node, XPathConstants.NODESET);
    }
1035640
void normalize(String expression)
    {
        final XPath xPath = XPathFactory.newInstance().newXPath();
        try
        {
            final NodeList nodeList = (NodeList) xPath.evaluate(expression, document, XPathConstants.NODESET);
            for (int i = 0; i < nodeList.getLength(); ++i)
            {
                final Node node = nodeList.item(i);
                node.getParentNode().removeChild(node);
            }
        }
        catch (final XPathExpressionException exception)
        {
            Verbose.exception(exception);
        }
    }
1088805
public static Element stringToElement(String xml) throws Exception {
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document d = builder.parse(bais);
      bais.close();
      return d.getDocumentElement();
   }
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));
    }
459023
public static XPath parse(String xpath) throws IllegalArgumentException {
        XPath xp = new XPath();

        // save the xpath as the full xpath
        xp.fullXPath = xpath;
        
        // does the xpath end with /*
        if (xpath.length() >= 2 && xpath.endsWith("/*")) {
            xp.includeChildren = true;
            xpath = xpath.substring(0, xpath.length()-2);
        }

        // normalized path is the rest
        xp.normalizedXPath = xpath;

        return xp;
    }
1269752
public @Nonnull Stream<XQuery> select(String xpath) {
        return new NodeListSpliterator(evaluate(xpath)).stream().map(XQuery::new);
    }
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 "";
    }
118961
private NodeList getNodeList(String document, XPathExpression expression) throws Exception
   {
      Document doc = m_documentBuilder.parse(new InputSource(new StringReader(document)));
      return (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
   }