Tuesday, January 12, 2010

LINQ to XML tiny sample


// load from file
XElement resp = XElement.Load("RCExtResponse.xml");
var all = from r in resp.Descendants()
          where r.Attributes().Count() == 0
          select r;

// or load from string
XElement xe = XElement.Parse(xmlString);

// use default

var caller =
    (from e in xe.Descendants("PracticeName")
     select (String)e).DefaultIfEmpty("");


No comments:

Post a Comment