Linq to XML and Dynamic Order By

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Our client has asked us to Order a set of XML elements by sending us the Order specification in the XML.
e.g.
<SortOrder1>Country</SortOrder1>
<SortOrder1FirstChar>1</SortOrder1FirstChar>
<SortOrder1FirstChar>5</SortOrder1FirstChar>
In this case, we need to Order By the first 5 characters of the Element whose name is Country
e.g.
<Data>
<Country>UK</Country>
</Data><
<Data>
<Country>Australia</Country>
</Data>
There may be other sort criteria,
<SortOrder2>Reference</SortOrder2>
<SortOrder2FirstChar>3</SortOrder2FirstChar>
<SortOrder2FirstChar>8</SortOrder2FirstChar>
My question is, can this type of dynamic Order By clause be generated and if so, how can this be done?
Any help would be gratefully received and appreciated
Mike

View the full article
 
Back
Top