8
Reply

Sorting XML

Adam Turner

Adam Turner

Jun 8 2011 3:07 PM
1.4k
I'm trying to sort some XML in C# that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<websites>
    <site language="Spanish" name="Excélsior" order="2">http://www.excelsior.com.mx/</site>
    <site language="Japanese" name="TOKYO Web" order="3">http://www.tokyo-np.co.jp/</site>
    <site language="Italian" name="Corriere della Sera" order="1">http://www.corriere.it/</site>
    <site language="Spanish" name="SpanishTest1" order="4">www.spanishtest1.com</site>
</websites>

I'm trying to implement a feature that will allow a user to sort the websites by their language. The order of the websites should reflect the language, and the language should be sorted alphabetically. I'm completely stuck on how to do this.


So in theory it should probably look like this after a sort:
<?xml version="1.0" encoding="UTF-8"?>
<websites> 
    <site language="Italian" name="Corriere della Sera" order="1">http://www.corriere.it/</site>
    <site language="Japanese" name="TOKYO Web" order="2">http://www.tokyo-np.co.jp/</site>
    <site language="Spanish" name="Excélsior" order="3">http://www.excelsior.com.mx/</site> 
    <site language="Spanish" name="SpanishTest1" order="4">www.spanishtest1.com</site> 
</websites>


Answers (8)