Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我如何循环使用这个XPathNodeIterator并随机化它的子对象?_C#_Xslt_Xpath_Xpathnavigator_Xpathnodeiterator - Fatal编程技术网

C# 我如何循环使用这个XPathNodeIterator并随机化它的子对象?

C# 我如何循环使用这个XPathNodeIterator并随机化它的子对象?,c#,xslt,xpath,xpathnavigator,xpathnodeiterator,C#,Xslt,Xpath,Xpathnavigator,Xpathnodeiterator,根据标题,我需要在C#/.NET4中创建一个方法,该方法可以混淆XPathNodeIterator对象的顺序。该方法需要循环遍历所有子项(“/*”),以随机重新排序子项 我需要一些帮助才能开始-我所拥有的只是方法存根: public XPathNodeIterator RandomizeXPathNodeIterator(XPathNodeIterator iterator) 感谢您的帮助! 谢谢您可以将XPathNodeIterator迭代为: XPathNavigator[] po

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

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

public XPathNodeIterator RandomizeXPathNodeIterator(XPathNodeIterator iterator)
感谢您的帮助!
谢谢

您可以将XPathNodeIterator迭代为:

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

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

        i++;
    }

然后,对数组进行筛选

您的目标是哪个.NET版本?获取所选节点的计数:
count(YourExpression)
设为
N
。然后在C#中生成从1到N的不同整数的随机序列(这不是XPath问题,尽管可以使用XSLT实现)。然后迭代迭代器,并保持迭代器当前位置的计数。填充节点数组(列表),使当前节点占据各自的数组位置,即随机序列中的位置,其值为当前节点在迭代器中的位置。如何将XPathNavigator[]位置重新设置为XPathNodeIterator?
XPathNodeIterator
是一个抽象类,如果您确实希望或需要方法返回一个
XPathNodeIterator
,那么您必须通过自己的具体实现来扩展该抽象类,该实现覆盖抽象方法和属性(例如
Count
Current
MoveNext
…)。然后,您的方法可以创建具体实现的实例并返回它。