Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 24, 2012 10:03 AM by kuber.manral
Member
10 Points
12 Posts
Feb 23, 2012 09:49 AM|LINK
Hi Guys,
How can i sort the xml in ascending or descending order while creating and updating xml file without using xslt and xpath.
please help.
All-Star
86685 Points
9634 Posts
Moderator
MVP
Feb 23, 2012 01:13 PM|LINK
Use LINQ-to-XML and the sort method:
http://msdn.microsoft.com/en-us/vstudio/bb738051
Contributor
3051 Points
714 Posts
Feb 24, 2012 10:03 AM|LINK
Hi,
try below Code for Sorting using LINQ to XML..
XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath("~/Data/Customers.xml")); return Convert.ToInt32( (from c in data.Descendants("Customer") orderby Convert.ToInt32(c.Attribute("ID").Value) descending select c.Attribute("ID").Value).FirstOrDefault() ) + 1;
kiranmoolya
Member
10 Points
12 Posts
sorting xml file in ascending or descending order
Feb 23, 2012 09:49 AM|LINK
Hi Guys,
How can i sort the xml in ascending or descending order while creating and updating xml file without using xslt and xpath.
please help.
DarrellNorto...
All-Star
86685 Points
9634 Posts
Moderator
MVP
Re: sorting xml file in ascending or descending order
Feb 23, 2012 01:13 PM|LINK
Use LINQ-to-XML and the sort method:
http://msdn.microsoft.com/en-us/vstudio/bb738051
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
kuber.manral
Contributor
3051 Points
714 Posts
Re: sorting xml file in ascending or descending order
Feb 24, 2012 10:03 AM|LINK
Hi,
try below Code for Sorting using LINQ to XML..
XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath("~/Data/Customers.xml")); return Convert.ToInt32( (from c in data.Descendants("Customer") orderby Convert.ToInt32(c.Attribute("ID").Value) descending select c.Attribute("ID").Value).FirstOrDefault() ) + 1;Visit My Blog