Sort tags in a xElement

Hello there,

I’m trying to sort this xml file :

so that the Ntry elements are in descending order (the file is simplified, but I have + 200 Ntry elements).

In this case, I want the Ntry element containing 2635400405324088
before the
2635400405358333

Is it possible ? The result would still be a xElement variable.

I have already deserialized the file with the concerned activity.

Thank you in advance and best wishes.

Ludovic

Hello @ludovic.vetter try this linq approach
xml.Descendants("Stmt").ToList().ForEach(s=>s.ReplaceNodes(s.Elements().Where(e=>e.Name != "Ntry").Concat(s.Elements("Ntry").OrderByDescending(n=>(long)n.Element("AcctSvcrRef")))));

Cheers

Hello, you’re a machine :slight_smile: though I have a lot of errors when doing that :

(sorry it’s in french :roll_eyes:)

Okayy I use LLM to translate and try this
xml.Descendants("Stmt").ToList().ForEach(Sub(stmt) stmt.ReplaceNodes(stmt.Elements().Where(Function(e) e.Name<>"Ntry").Concat(stmt.Elements("Ntry").OrderByDescending(Function(n) CLng(n.Element("AcctSvcrRef"))))) End Sub)
Cheers

@ludovic.vetter,

May I know what’s the end goal here? As per my understanding this looks like a bank statement which we reconcile with some internal data.

If you have already deserialized the data, I would suggest to put it in a datatable or excel file and then do the sorting.

@ludovic.vetter

If you have already deserialized then sorting after that makes sense

it would order but that piece of xml will be ordered

cheers