如何有条件地读取所有属性?
How to read all attributes conditionally?
我想使用 where 子句将所有属性读取为 IEnumerable。
所以我想要的是 -
return Employee as List 其中 List = 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>
你System.Xml.Linq XElement class
XElement xml = XElement.Load("filePath");
var payList = xml.Elements("Lists").Where(list => list.Attribute("List").Value == "PayList");
我想使用 where 子句将所有属性读取为 IEnumerable。
所以我想要的是 -
return Employee as List 其中 List = 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>
你System.Xml.Linq XElement class
XElement xml = XElement.Load("filePath");
var payList = xml.Elements("Lists").Where(list => list.Attribute("List").Value == "PayList");