In C#, I sorted an RSS feed using XpathExpression and a self defined compare function for the field Publication Date.
I need to convert this sorted XPathNodeIterator object to a List<XElement> 'Generic Linq type' object. I've tried to use an intermediary data-type but did not have any luck.
Tried:
List<XElement> elements = new List<XElement>();
IEnumerable<XElement> sortedElements;
IEnumerable<XElement> newElements;
sortedElements = (IEnumerable <XElement>) iterator;
I've also tried using order by on the list but that was unsuccessful using only List<XElement>.
Since this is an
IEnumerable, the easiest way to convert to anIEnumerable<>is to useOfType, like this:This will not give you
XElementobjects; that's part of a separate XML API. However, theXPathNavigatorobjects may have the data you need, so you can follow up with some sort ofSelectdepending on what you need:If you do want to use
System.Linq.Xmlstuff, you may be able to rewrite your XPath as LINQ on anXDocumentinstead.