Reputation: 2107
I need to change the order of elements in one parent element. So it is easy to get sorted elements.
myXML.Elements("Issue").OrderBy(x => int.Parse(x.Attribute("id").Value));
But I need to return this sorted collection back in myXML XElement without affecting it's structure.
How to do this?
Upvotes: 0
Views: 132
Reputation: 1500675
It sounds like you just want:
// No need to specify "Issue" if that's all that's in myXML. Prefer explicit
// attribute conversion over "manual" parsing
var orderedIssues = myXML.Elements().OrderBy(x => (int) x.Attribute("id"));
myXML.ReplaceNodes(orderedIssues);
Upvotes: 2