2016-12-29 56 views
-1

我想使用where子句作爲IEnumerable讀取所有屬性。如何有條件讀取所有屬性?

所以,我想要的是 -

回報員工的名單,其中列出= PayList

下面是我的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> 

回答

0

您System.Xml.Linq的的XElement類

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

感謝@Mehmet。但是,它表示 - 枚舉不會產生任何價值 –