Tuesday, September 8, 2009

Manipulating Xml with C#

I'm pretty fond of the XDocument class. XDocument lets you have your way with XML without requiring convoluted syntax, especially when used in conjunction with lambda expressions. Here's an example to change the value of an attribute on nodes that were found through a search criterion.


XDocument xDoc = XDocument.Load(

    new StringReader(

        @"<Customers><Customer ID=""99"" Description=""Just another customer""></Customer></Customers>"));

xDoc.Descendants("Customer").ToList().

    ForEach

    (e =>

        {

            if (e.Attribute("ID").Value == "99")

            { e.Attribute("Description").Value = "Our best customer"; }

        }

    );



3 comments:

Anonymous said...

Wow, that's what I was seeking for, what a stuff! present here at this weblog, thanks admin of this website.
Also visit my web page ... online loans

Anonymous said...

Keep on working, great job!

Also visit my webpage ... you have to see this

Anonymous said...

Hi there! I could have sworn I've been to this site before but after looking at some of the posts I realized it's
new to me. Regardless, I'm definitely delighted I discovered it and I'll be book-marking it and
checking back regularly!

Here is my page; online payday loans