CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    6

    Sorting some XML in C#

    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>

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Sorting some XML in C#

    Just guess, but LINQ to XML wouldn't help? Because it seems to me that you don't want to sort the XML, but the XML Document buit in the memory.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured