//I dont seem to find the DESC element mentioned in you recent post, hence am caryying forward it
// with below XML only. Lets say you want to delete the element having name="WIN"
string mySchedules = "<showschedule>" +
"<fall name=\"FAL\" text=\"Y\" index=\"3\"/>" +
"<spring name=\"SPR\" text=\"Y\" index=\"2\"/>" +
"<winter name=\"WIN\" text=\"Y\" index=\"1\"/>" +
"<summer name=\"SUM\" text=\"Y\" index=\"4\"/>" +
"</showschedule>";
XElement xShows = XElement.Parse(mySchedules);
IEnumerable<XElement> singleSchedule = from s in xShows.Descendants()
where ((string)s.Attribute("name").Value.ToLower()).Equals("win")
select s;
singleSchedule.Remove();
string myOutput = xShows.ToString();
///*
// It will give you output as ::see the text of Winter.::
// *
// * <showschedule>
// <fall name="FAL" text="Y" index="3"/>
// <spring name="SPR" text="Y" index="2"/>
// <summer name="SUM" text="Y" index="4"/>
// </showschedule>
// *
// */
Please mark this post as Answer if it is of help to you!
I would love to change the world, but they wont give me the source code.
Marked as answer by Bee90124 on Apr 13, 2012 02:03 PM
kavita_khand...
Star
9767 Points
1930 Posts
Re: LINQ to XML specific question on extracting data
Apr 13, 2012 05:27 AM|LINK
//I dont seem to find the DESC element mentioned in you recent post, hence am caryying forward it // with below XML only. Lets say you want to delete the element having name="WIN" string mySchedules = "<showschedule>" + "<fall name=\"FAL\" text=\"Y\" index=\"3\"/>" + "<spring name=\"SPR\" text=\"Y\" index=\"2\"/>" + "<winter name=\"WIN\" text=\"Y\" index=\"1\"/>" + "<summer name=\"SUM\" text=\"Y\" index=\"4\"/>" + "</showschedule>"; XElement xShows = XElement.Parse(mySchedules); IEnumerable<XElement> singleSchedule = from s in xShows.Descendants() where ((string)s.Attribute("name").Value.ToLower()).Equals("win") select s; singleSchedule.Remove(); string myOutput = xShows.ToString(); ///* // It will give you output as ::see the text of Winter.:: // * // * <showschedule> // <fall name="FAL" text="Y" index="3"/> // <spring name="SPR" text="Y" index="2"/> // <summer name="SUM" text="Y" index="4"/> // </showschedule> // * // */I would love to change the world, but they wont give me the source code.