我如何循环XPathNodeIterator并随机化其子项?

时间:2012-10-22 11:37:21

标签: c# xslt xpath xpathnavigator xpathnodeiterator

根据标题,我需要在C#/ .NET 4中创建一个方法,它可以混杂XPathNodeIterator对象的顺序。该方法需要遍历所有子项(“/ *”)以随机重新排序子项。

我需要一些帮助才能开始 - 我所拥有的只是方法存根:

public XPathNodeIterator RandomizeXPathNodeIterator(XPathNodeIterator iterator)

任何帮助表示赞赏! 感谢

1 个答案:

答案 0 :(得分:0)

您可以将XPathNodeIterator迭代为:

    XPathNavigator[] positions = new XPathNavigator[iterator.Count];
    int i = 0;

    while (iterator.MoveNext())
    {
        XPathNavigator n = iterator.Current;
        positions[i] = n;

        i++;
    }

然后,搜索数组