LINQ XML选择内部选择
本文关键字:选择 内部 XML LINQ | 更新日期: 2023-09-27 18:12:36
我有以下xml:
<transactionSearchResult>
<resultsInThisPage>14</resultsInThisPage>
<currentPage>1</currentPage>
<totalPages>1</totalPages>
<date>2011-10-28T11:20:10.000-02:00</date>
<transactions>
<transaction>
<date>2011-06-17T18:21:03.000-03:00</date>
<reference>ba3b7d36-a9e6-4d48-82b8-edf31a18fa49</reference>
<code>4E63AE64-24CF-4F70-A275-4B964E3DA6A5</code>
<type>1</type>
<status>4</status>
<paymentMethod>
<type>1</type>
</paymentMethod>
<grossAmount>1.00</grossAmount>
<discountAmount>0.00</discountAmount>
<feeAmount>0.46</feeAmount>
<netAmount>0.54</netAmount>
<extraAmount>0.00</extraAmount>
<lastEventDate>2011-07-01T19:27:36.000-03:00</lastEventDate>
</transaction>
<transaction>
.
.
.
</transaction>
.
.
.
linq语句
<>之前var transactions = from transaction in xml.Descendants("transaction")选择新{code = transaction.Element("code").Value,reference = transaction.Element("reference").Value,date = transaction.Element("date").Value,type = transaction.Element("type"),status = transaction.Element("status"),grossAmount = transaction.Element("grossAmount").Value,discountAmount = transaction.Element("discountAmount").Value,feeAmount = transaction.Element("feeAmount").Value,netAmount = transaction.Element("netAmount").Value,extraAmount = transaction.Element("extraAmount").Value,lastEventDate = transaction.Element("lastEventDate").Value,paymentMethod = from transaction.Descendants("paymentMethod")中的p选择p.Element("类型")value};之前你在寻找更像这样的东西吗?
paymentMethod = int.Parse(transaction.Element("paymentMethod").Element("type").Value)