2011-10-28 37 views
0

を選択する内部選択:LINQのXML私は次の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なステートメント:PAYMENTMETHOD以外

 
    var transactions = from transaction in xml.Descendants("transaction") 
      select new 
      { 
       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 p in transaction.Descendants("paymentMethod") 
            select p.Element("type").Value};

を、すべてが正常に動作します...

+0

paymentMethodはどのように見えますか?それはどんなタイプですか? – StriplingWarrior

答えて

1

あなたは何かを探していますもっとこれのような?

paymentMethod = int.Parse(transaction.Element("paymentMethod").Element("type").Value) 
+0

はい!どうもありがとうございました!私はそれが欲しいのと同じように動作します! – ShadowG

+1

'payMethod =(int)(transaction.Element(" paymentMethod ")。要素(" type "))' –

+0

@JimWooley:このヒントをありがとう。 XElementsを暗黙的にキャストすることができるかどうかはわかりませんでした。 – StriplingWarrior

関連する問題