How do i loop thourgh XPathNodeIterator and randomize its children?
-
13-07-2021 - |
Question
As per title, i need to create a method in C#/.NET 4 that can jumble the order a XPathNodeIterator object. The method needs to loop though all the child items ("/*") to randomly reorder the children.
I need some help to some to get started - All i have is the method stub:
public XPathNodeIterator RandomizeXPathNodeIterator(XPathNodeIterator iterator)
Any help is appreciated! Thanks
La solution
You can iterate XPathNodeIterator as:
XPathNavigator[] positions = new XPathNavigator[iterator.Count];
int i = 0;
while (iterator.MoveNext())
{
XPathNavigator n = iterator.Current;
positions[i] = n;
i++;
}
Then, scrumble the array
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow