protected AnyType evaluateSimpleXPath(String xpath, Document doc, Class resultClass) {
    try {
      compileXPath(xpath);
    } catch (XPathParserException e) {
      throw new RuntimeException("XPath parse: " + e.getMessage(), e);
    } catch (StaticError e) {
      throw new RuntimeException("Static error: " + e.getMessage(), e);
    }

    ResultSequence rs;
    try {
      rs = evaluate(domDoc);
    } catch (DynamicError e) {
      throw new RuntimeException("Evaluation error: " + e.getMessage(), e);
    }
    assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());

    AnyType result = rs.first();
    assertTrue(
        "Exected XPath result instanceof class "
            + resultClass.getSimpleName()
            + " from \'"
            + xpath
            + "\', got "
            + result.getClass(),
        resultClass.isInstance(result));

    return result;
  }
  // How many top-level sections are in Book1?
  public void test_tree_queries_results_q4() throws Exception {
    String inputFile = "/TestSources/book.xml";
    String xqFile = "/Queries/XQuery/UseCase/UseCaseTREE/tree-queries-results-q4.xq";
    String resultFile = "/ExpectedTestResults/UseCase/UseCaseTREE/tree-queries-results-q4.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);

    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();

    setupDynamicContext(schema);

    String xpath = "count($input-context/book/section)";
    String actual = null;
    try {
      compileXPath(xpath);
      ResultSequence rs = evaluate(domDoc);

      actual = "<top_section_count>" + buildResultString(rs) + "</top_section_count>";

    } catch (XPathParserException ex) {
      actual = ex.code();
    } catch (StaticError ex) {
      actual = ex.code();
    } catch (DynamicError ex) {
      actual = ex.code();
    }

    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
  }
  // Evaluates the "days-from-duration" function with the arguments set as follows: $arg =
  // xs:dayTimeDuration(upper bound).
  public void test_fn_days_from_duration1args_3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile =
        "/Queries/XQuery/Functions/DurationDateTimeFunc/DaysFromDurationFunc/fn-days-from-duration1args-3.xq";
    String resultFile =
        "/ExpectedTestResults/Functions/DurationDateTimeFunc/DaysFromDurationFunc/fn-days-from-duration1args-3.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);

    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();

    setupDynamicContext(schema);

    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
      compileXPath(xpath);
      ResultSequence rs = evaluate(domDoc);

      actual = buildResultString(rs);

    } catch (XPathParserException ex) {
      actual = ex.code();
    } catch (StaticError ex) {
      actual = ex.code();
    } catch (DynamicError ex) {
      actual = ex.code();
    }

    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
  }
  // Simple evaluation of sequence type matching involving instance of and a sequence of decimal.
  public void test_sequence_type_3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Basics/Types/SequenceTypeSyntax/sequence-type-3.xq";
    String resultFile = "/ExpectedTestResults/Basics/Types/SequenceTypeSyntax/truevalue.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);

    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();

    setupDynamicContext(schema);

    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
      compileXPath(xpath);
      ResultSequence rs = evaluate(domDoc);

      AnyType result = rs.first();

      actual = result.getStringValue();
    } catch (XPathParserException ex) {
      actual = ex.code();
    } catch (StaticError ex) {
      actual = ex.code();
    }

    assertEquals("XPath Result Error:", expectedResult, actual);
  }