Java Code Examples for javax.xml.xpath.XPathExpression#evaluateExpression()

The following examples show how to use javax.xml.xpath.XPathExpression#evaluateExpression() . 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: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "document")
public void test05(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("count(/Customers/Customer)");
    double result1 = exp.evaluateExpression(doc, Double.class);
    assertTrue(result1 == 3.0);

    int result2 = exp.evaluateExpression(doc, Integer.class);
    assertTrue(result2 == 3);
}
 
Example 2
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "document")
public void test07(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("/Customers/Customer");
    XPathNodes nodes = exp.evaluateExpression(doc, XPathNodes.class);
    assertTrue(nodes.size() == 3);
    for (Node n : nodes) {
        assertEquals(n.getLocalName(), "Customer");
    }
}
 
Example 3
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
public void test02(XPath xpath) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("1+1");
    double result = exp.evaluateExpression((Object)null, null);
}
 
Example 4
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "xpath")
public void test03(XPath xpath) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("1+1");
    int result = exp.evaluateExpression((Object)null, Integer.class);
    assertTrue(result == 2);
}
 
Example 5
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test04(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("boolean(/Customers/Customer[@id=3])");
    boolean result1 = exp.evaluateExpression(doc, Boolean.class);
    assertTrue(result1);
}
 
Example 6
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test06(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("string(/Customers/Customer[@id=3]/Phone/text())");
    String result1 = exp.evaluateExpression(doc, String.class);
    assertTrue(result1.equals("3333333333"));
}
 
Example 7
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test08(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("/Customers/Customer[@id=3]");
    Node n = exp.evaluateExpression(doc, Node.class);
    assertEquals(n.getLocalName(), "Customer");
}
 
Example 8
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document", expectedExceptions = IllegalArgumentException.class)
public void test09(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("/Customers/Customer[@id=3]");
    File n = exp.evaluateExpression(doc, File.class);
}
 
Example 9
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test10(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("boolean(/Customers/Customer[@id=3])");
    XPathEvaluationResult<?> result = exp.evaluateExpression(doc);
    verifyResult(result, true);
}
 
Example 10
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test11(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("count(/Customers/Customer)");
    XPathEvaluationResult<?> result = exp.evaluateExpression(doc);
    verifyResult(result, 3.0);
}
 
Example 11
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test12(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("string(/Customers/Customer[@id=3]/Phone/text())");
    XPathEvaluationResult<?> result = exp.evaluateExpression(doc, XPathEvaluationResult.class);
    verifyResult(result, "3333333333");
}
 
Example 12
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test13(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("/Customers/Customer");
    XPathEvaluationResult<?> result = exp.evaluateExpression(doc);
    verifyResult(result, "Customer");
}
 
Example 13
Source File: XPathExpAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test14(XPath xpath, Document doc) throws XPathExpressionException {
    XPathExpression exp = xpath.compile("/Customers/Customer[@id=3]");
    XPathEvaluationResult<?> result = exp.evaluateExpression(doc);
    verifyResult(result, "Customer");
}