Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘linq2xml LINQ example xml c#’

LINQ2XML Example

Posted by Paul on November 21, 2011

This is one of the code sample which I worked over a forum.

From the xml file given below, we need to select the nodes with category attribute of value pending.


  <fault category=”pending”>
    <text>Pending Fault found on</text>
  <fault category=”repaired”>
    <text>Repaired Fault on</text>


Following the LINQ2XML Code to attain the same:


XElement xElement = XElement.Load(@”c:\\temp\\xml.txt”);
            var list = (from e in xElement.Elements(“fault”) where e.Attribute(“category”).Value == “pending”
                 select e).ToList();

            foreach (XElement xe in list)



Posted in C#, Design Patterns | Tagged: | Leave a Comment »