Search in sources :

Example 71 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_27.

// Evaluates unabbreviated syntax. Evaluate
// "/child::works/child::employee[fn:position() = 5]/child::hours[fn:position() = 2]".
// Selects the second "hours" of the fifth "employee" of the "works" whose
// parent is the document node that contains the context node.
public void test_unabbreviatedSyntax_27() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-27.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-27.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        actual = buildXMLResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 72 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_Axes079_2.

// elem//node() gets 1 child element.
public void test_Axes079_2() throws Exception {
    String inputFile = "/TestSources/Tree1Child.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes079.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes079-2.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        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);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 73 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_nodeexpression3.

// Evaluation of a Node expression With the operands/operator set with the
// following format: empty Sequence is Single Node Element.
public void test_nodeexpression3() throws Exception {
    String inputFile = "/TestSources/works.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/NodeOp/NodeSame/nodeexpression3.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/NodeOp/NodeSame/nodeexpression3.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        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);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 74 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_predicates_6.

// Evaluation of a simple predicate set to a boolean expression ("and"
// operator), returns false. Use "fn:count" to avoid empty file.
public void test_predicates_6() throws Exception {
    String inputFile = "/TestSources/atomicns.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Predicates/predicates-6.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Predicates/predicates-6.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        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);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 75 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_predicates_3.

// Evaluation of a simple predicate with a "true" value (uses "fn:true" and
// fn:not()).
public void test_predicates_3() throws Exception {
    String inputFile = "/TestSources/atomicns.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Predicates/predicates-3.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Predicates/predicates-3.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        actual = buildXMLResultString(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);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Aggregations

XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)77 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)75 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)75 URL (java.net.URL)73 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)73 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)73 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)73 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)72 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)72 XSModel (org.apache.xerces.xs.XSModel)69 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)20 Item (org.eclipse.wst.xml.xpath2.api.Item)17 Iterator (java.util.Iterator)13 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 Collection (java.util.Collection)10 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)6 Duration (javax.xml.datatype.Duration)5