Code example for XPathExpression

Methods: evaluate

    assertTrue("Asserting there are state-data records for Electric system.",  
        (Boolean) hasElectricData);
    XPathExpression hasPhotovoltaicDataExpr = xpath.compile(
      "count(//state-data[@system='PHOTOVOLTAIC']) > 0"); 
    Object hasPhotovoltaicData = hasPhotovoltaicDataExpr.evaluate(doc, XPathConstants.BOOLEAN);
    assertTrue("Asserting there are state-data records for Photovoltaic system.",  
      (Boolean) hasPhotovoltaicData);
    // Retrieve the first state-data record, and its timestamp should be the base timestamp 
    // value used to create historical state-data record. i.e., (base timestamp - 1 minute) is a  
    // record 1 minute in the past. 
    XPathExpression firstStateDataNodeExpr = xpath.compile("//state-data[1]");
    Object firstStateDataNode = firstStateDataNodeExpr.evaluate(doc, XPathConstants.NODE);
    final long baseTimestamp = Long.valueOf(
        ((Element) firstStateDataNode).getAttribute("timestamp"));
    String expression = "count(//state-data[@timestamp=" + baseTimestamp + "]) > 0";
    XPathExpression baseTimestampCountExpr = xpath.compile(expression);
    Object recordWithBaseTimtestamp = baseTimestampCountExpr.evaluate(doc, XPathConstants.BOOLEAN);
Stop searching for code, let great code find you!  Add Codota to your java IDE