Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator content is missing in variable #6

Open
nverwer opened this issue May 1, 2017 · 1 comment
Open

Iterator content is missing in variable #6

nverwer opened this issue May 1, 2017 · 1 comment

Comments

@nverwer
Copy link

nverwer commented May 1, 2017

Node iterators do not work correctly when one of the items is a variable containing the result of a previous XPath2 evaluation. I added the following test to XPath2ExtensionsTest (not the right place):

    public void XPath2_IteratorWithVariableTest()
    {
        System.Collections.Generic.Dictionary<XmlQualifiedName, object> vars = new System.Collections.Generic.Dictionary<XmlQualifiedName, object>();
        var nav = GetTodoListDoc().CreateNavigator();
        var prov = new NodeProvider(nav);
        var result = nav.XPath2Evaluate("/todo-list/todo-item[1]");
        vars[new XmlQualifiedName("x")] = result;
        var expr = XPath2Expression.Compile("($x, /todo-list/todo-item[2])");
        result = expr.Evaluate(prov, vars);
        vars[new XmlQualifiedName("y")] = result;
        expr = XPath2Expression.Compile("($y, /todo-list/todo-item[3])");
        result = expr.Evaluate(prov, vars);
        vars[new XmlQualifiedName("z")] = result;
    }

After every evaluation, the result contains only one item, which is the selected node. I would expect the result to contain 3 items at the end. The contents of the variable are lost.

@nverwer
Copy link
Author

nverwer commented May 1, 2017

If I 'solidify' the result after evaluating an expression, using

result = BufferedNodeIterator.Preload(result as XPath2NodeIterator);

the test seems to work.
The problem is, that before making the result into a BufferedNodeIterator, result.Count is incorrect.
Then I tried to make the result into a list before assigning it to a variable:

result = (result as XPath2NodeIterator).ToList();

This works, and the Count is right.
Is this the recommended way of storing an iterator in a variable?

@nverwer nverwer changed the title Iterator is not initialized correctly Iterator content is missing in variable May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant