How to read all attributes conditionally?

24 views Asked by At

I want to read all attributes as IEnumerable using where clause.

So what I want is -

return Employee as List where List = PayList

Below is my XML.

<Employees Table="ListColumns" StartAt="1" Output="Return">
  <Lists List="PayList">
    <Employee Start="51" Length="11" Name="Amount"/>
    <Employee Start="62" Length="6" Name="Name"/>
    <Employee Start="68" Length="50" Name="Reason"/>
    <Employee Start="118" Length="7" Name="Action"/>
    <Employee Start="125" Length="6" Name="First"/>
    <Employee Start="131" Length="6" Name="Last"/>
    <Employee Start="137" Length="40" Name="Payee"/>
    <Employee Start="177" Length="6" Name="Banker"/>
    <Employee Start="183" Length="19" Name="DateIssued"/>
    <Employee Start="202" Length="19" Name="DateStopped"/>
  </Lists>
  <Lists List="ResponseList">
    <Employee Start="51" Length="11" Name="Amount"/>
    <Employee Start="62" Length="6" Name="Name"/>
    <Employee Start="68" Length="50" Name="Reason"/>
    <Employee Start="118" Length="7" Name="Action"/>
    <Employee Start="125" Length="6" Name="First"/>
    <Employee Start="131" Length="6" Name="Last"/>
    <Employee Start="137" Length="40" Name="Payee"/>
    <Employee Start="177" Length="6" Name="Banker"/>
    <Employee Start="183" Length="19" Name="DateIssued"/>
    <Employee Start="202" Length="19" Name="DateStopped"/>
  </Lists>
</Employees>
1

There are 1 answers

1
Mehmet On BEST ANSWER

You System.Xml.Linq XElement class

      XElement xml = XElement.Load("filePath");
      var payList = xml.Elements("Lists").Where(list => list.Attribute("List").Value == "PayList");