Assert that the evaluation of two Xpaths in the same document are equal
@param controlXpath
@param testXpath
@param document
@see XpathEngine
166758
public static void assertXpathValuesEqual(String controlXpath,
                                              String testXpath,
                                              Document document)
        throws XpathException {
        assertXpathValuesEqual(controlXpath, document, testXpath, document);
    }
791177
public static void assertXpathsNotEqual(String controlXpath,
                                            InputSource controlDocument,
                                            String testXpath,
                                            InputSource testDocument)
        throws SAXException, IOException, XpathException {
        assertXpathsNotEqual(controlXpath,
                             XMLUnit.buildControlDocument(controlDocument),
                             testXpath,
                             XMLUnit.buildTestDocument(testDocument));
    }
113431
public boolean notEquals(XObject obj2)
          throws javax.xml.transform.TransformerException
  {

    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.notEquals(this);

    return !equals(obj2);
  }
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);
        }
    }
1312795
public static XPathUtils newXPath(final Document doc) {
        final XPathFactory xpfactory = XPathFactory.newInstance();
        final XPath xPath = xpfactory.newXPath();
        return new XPathUtils(xPath, doc);
    }
660134
private DeferredComparison compareAttributeExplicitness(final Attr control,
                                                            final XPathContext controlContext,
                                                            final Attr test,
                                                            final XPathContext testContext) {
        return new DeferredComparison() {
            @Override
            public ComparisonState apply() {
                return compare(new Comparison(ComparisonType.ATTR_VALUE_EXPLICITLY_SPECIFIED,
                                              control, getXPath(controlContext),
                                              control.getSpecified(), getParentXPath(controlContext),
                                              test, getXPath(testContext),
                                              test.getSpecified(), getParentXPath(testContext)));
            }
        };
    }
244701
public static void assertXpathExists(String xPathExpression, 
                                         InputSource control)
        throws IOException, SAXException, XpathException {
        Document inDocument = XMLUnit.buildControlDocument(control);
        assertXpathExists(xPathExpression, inDocument);
    }
969476
public static void assertXpathNotExists(String xPathExpression, 
                                            Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        NodeList nodeList = simpleXpathEngine.getMatchingNodes(
                                                               xPathExpression, inDocument);
        int matches = nodeList.getLength();
        assertEquals("Should be zero matches for Xpath " + 
                     xPathExpression, 0, matches);
    }
430488
public static void assertXMLEqual(InputSource control, InputSource test)
        throws SAXException, IOException {
        assertXMLEqual(null, control, test);
    }
130209
function hasDirectTextDescendantXpath() {
        var selectorResults = ownerDocument.evaluate(axs.properties.TEXT_CONTENT_XPATH,
                                                     element,
                                                     null,
                                                     XPathResult.ANY_TYPE,
                                                     null);
        for (var resultElement = selectorResults.iterateNext();
             resultElement != null;
             resultElement = selectorResults.iterateNext()) {
            if (resultElement !== element)
                continue;
            return true;
        }
        return false;
    }
247349
private ComparisonState compareAttributes(Attr control,
                                              XPathContext controlContext,
                                              Attr test,
                                              XPathContext testContext) {
        return compareAttributeExplicitness(control, controlContext, test,
                                            testContext).apply()
            .andThen(new Comparison(ComparisonType.ATTR_VALUE,
                                    control, getXPath(controlContext),
                                    control.getValue(), getParentXPath(controlContext),
                                    test, getXPath(testContext),
                                    test.getValue(), getParentXPath(testContext)));
    }
1341935
public static void assertXMLNotEqual(Reader control, Reader test)
        throws SAXException, IOException {
        assertXMLNotEqual(null, control, test);
    }
309562
private ComparisonState compareXsiType(Attr controlAttr,
                                           XPathContext controlContext,
                                           Attr testAttr,
                                           XPathContext testContext) {
        boolean mustChangeControlContext = controlAttr != null;
        boolean mustChangeTestContext = testAttr != null;
        if (!mustChangeControlContext && !mustChangeTestContext) {
            return new OngoingComparisonState();
        }
        boolean attributePresentOnBothSides = mustChangeControlContext
            && mustChangeTestContext;

        try {
            QName controlAttrName = null;
            if (mustChangeControlContext) {
                controlAttrName = Nodes.getQName(controlAttr);
                controlContext.addAttribute(controlAttrName);
                controlContext.navigateToAttribute(controlAttrName);
            }
            QName testAttrName = null;
            if (mustChangeTestContext) {
                testAttrName = Nodes.getQName(testAttr);
                testContext.addAttribute(testAttrName);
                testContext.navigateToAttribute(testAttrName);
            }
            return
                compare(new Comparison(ComparisonType.ATTR_NAME_LOOKUP,
                                       controlAttr, getXPath(controlContext),
                                       controlAttrName, getParentXPath(controlContext),
                                       testAttr, getXPath(testContext),
                                       testAttrName, getParentXPath(testContext)))
                .andIfTrueThen(attributePresentOnBothSides,
                               compareAttributeExplicitness(controlAttr, controlContext,
                                                            testAttr, testContext))
                .andIfTrueThen(attributePresentOnBothSides,
                               new Comparison(ComparisonType.ATTR_VALUE,
                                              controlAttr, getXPath(controlContext),
                                              valueAsQName(controlAttr), getParentXPath(controlContext),
                                              testAttr, getXPath(testContext),
                                              valueAsQName(testAttr), getParentXPath(testContext)));
        } finally {
            if (mustChangeControlContext) {
                controlContext.navigateToParent();
            }
            if (mustChangeTestContext) {
                testContext.navigateToParent();
            }
        }
    }
1112121
public static String evaluate(XmlObject xmlbean, String path) {
        XmlCursor cursor = xmlbean.newCursor();
        String value;
        
// 1.2.3. use XQuery or selectPath
//
//        cursor.toFirstChild();
//        String defaultNamespace = cursor.namespaceForPrefix("");
//        String namespaceDecl = "declare default element namespace '" + defaultNamespace + "';";
//        Map<String,String> namespaces = new HashMap<String,String>();
//        cursor.getAllNamespaces(namespaces);
//        for (String prefix : namespaces.keySet())
//        {
//            namespaceDecl += "declare namespace " + prefix + "='" + namespaces.get(prefix) + "';";
//        }
//  1. use XQuery
//        XmlCursor results = cursor.execQuery(namespaceDecl + path);
//        value = (results==null)?null:results.getTextValue();
        
//  2. use selectPath on XmlObject
//        XmlObject[] result = xmlbean.selectPath(namespaceDecl + path);
        
//  3. use selectPath on XmlCursor   
//        cursor.toParent();
//        XmlOptions options = new XmlOptions();
//        options.put(Path.PATH_DELEGATE_INTERFACE,"org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath");
//        cursor.selectPath(namespaceDecl + path, options);
//        if (cursor.getSelectionCount()>0) {
//            cursor.toNextSelection();
//            value = cursor.getTextValue();
//        } else value = null;

// 4. use our own implementation
        try {
            XmlPath matcher = new XmlPath(path);
            value = matcher.evaluate_segment(cursor, matcher.path_seg);
        } catch (XmlException e) {
            value = null; // xpath syntax error - treated as no match
        }
        
        cursor.dispose();
        return value;
    }
102809
public static NodeList xpathNodeList(Node document, String xpathExpression, Map<String, String> namespaceMapping) throws XPathException,
                MarshallingException
    {
        return (NodeList) executeXPath(document, xpathExpression, namespaceMapping, XPathConstants.NODESET);
    }
818358
public String execute( String xPath ) throws Exception {

		if ( xPath == null ){
			return null;
		}
		
		// Evaluate the xpath expression
		return XPathAPI.eval( getDoc(), xPath ).toString();
		
	
	}
821825
public static String valueFromXPath(Document parsedXml, String path) {
		XPath xPath = XPathFactory.newInstance().newXPath();
		try {
			return xPath.evaluate(path, parsedXml.getDocumentElement());
		}
		catch (XPathExpressionException exception) {
			LOG.error("Incorrect xpath provided: " + path, exception);
			throw new IllegalArgumentException();
		}
	}