Just stumbled onto this combination.
XElement root = XElement.Parse(
@"<myxml>
<a/>
<b/>
<c/>
</myxml>");
root.Descendants().ToList().ForEach( delegate(XElement element){ element.Add( new XAttribute( "moo", "car" ) ); } );
Console.WriteLine( root );
Accepting the implications of .ToList'ing your LINQ query, this is some powerful stuff.
PS - If you don't know what I'm talking about with the whole "implications of .ToList'ing your LINQ query" you should really buy the LINQ Pocket Reference. And if you want to easily try the example you should download LINQPad. It's free, excellent, and written by the authors of the aforementioned book.
♦Add to del.icio.us ♦DiggIt! ♦Reddit ♦Stumble This ♦Add to Google Bookmarks ♦Add to Yahoo MyWeb ♦Add to Technorati Faves ♦Slashdot it
No comments:
Post a Comment