Cannot convert XPathNavigator to XPathNodeIterator
I am currently developing an Xslt extensions that randomly orders nodes.
I'm using the following approach, which works perfectly, no issues.
public static XPathNodeIterator RandomSet(XPathNodeIterator nodeset) { try { Random random = new Random();
List<int> numbers = new List<int>(nodeset.Count); for (int x = 1; x <= nodeset.Count; x++) numbers.Add(x);
List<int> randNumbers = new List<int>(nodeset.Count); for (int x = 0; x < nodeset.Count; x++) { int rn = random.Next(numbers.Count); int rnVal = numbers[rn]; randNumbers.Add(rnVal); numbers.RemoveAt(rn); }
XmlDocument xd = new XmlDocument(); xd.LoadXml("<values />"); foreach (int i in randNumbers) { XmlNode thisNumber = xd.CreateElement("value"); thisNumber.AppendChild(xd.CreateTextNode(i.ToString())); xd.DocumentElement.AppendChild(thisNumber); }
I am also trying to implement randomly ordering nodes using the approach below, which I feel is cleaner, but is causing the following error.
Cannot implicitly convert type
'System.Linq.IOrderedEnumerable<System.Xml.XPath.XPathNavigator>'
to 'System.Xml.XPath.XPathNodeIterator'
public static XPathNodeIterator RandomLinq(XPathNodeIterator nodeset) { try { var randomNodeset = from XPathNavigator node in nodeset orderby Guid.NewGuid() select node;
Cannot convert XPathNavigator to XPathNodeIterator
I am currently developing an Xslt extensions that randomly orders nodes.
I'm using the following approach, which works perfectly, no issues.
I am also trying to implement randomly ordering nodes using the approach below, which I feel is cleaner, but is causing the following error.
Cannot implicitly convert type 'System.Linq.IOrderedEnumerable<System.Xml.XPath.XPathNavigator>' to 'System.Xml.XPath.XPathNodeIterator'
Any ideas how to resolve the error?
is working on a reply...