尝试从下面的 XML 文件中提取值时遇到问题。我需要将以下值传递给 C# 对象:EXPR、DATE、ASK。我将使用 LINQ。我遇到了 EXPR 值的问题,因为它没有分组,我能得到的只是第一个值。有任何想法吗?
<RESPONSE>
<EXPR>USD</EXPR>
<EXCH>EUR</EXCH>
<AMOUNT>1</AMOUNT>
<NPRICES>1</NPRICES>
<CONVERSION>
<DATE>Sat, 02 Jun 2001 22:50:00 GMT</DATE>
<ASK>0.8484</ASK>
<BID>0.8479</BID>
</CONVERSION>
<EXPR>USD</EXPR>
<EXCH>CAD</EXCH>
<AMOUNT>1</AMOUNT>
<NPRICES>1</NPRICES>
<CONVERSION>
<DATE>Sat, 02 Jun 2001 15:54:57 GMT</DATE>
<ASK>0.6505</ASK>
<BID>0.6501</BID>
</CONVERSION>
<EXPR>USD</EXPR>
<EXCH>FRF</EXCH>
<AMOUNT>1</AMOUNT>
<NPRICES>1</NPRICES>
<CONVERSION>
<DATE>Thu, 31 Dec 1998 00:00:00 GMT</DATE>
<ASK>0.1779</ASK>
<BID>0.1779</BID>
</CONVERSION>
<EXPR>USD</EXPR>
<EXCH>DEM</EXCH>
<AMOUNT>1</AMOUNT>
<NPRICES>1</NPRICES>
<CONVERSION>
<DATE>Thu, 31 Dec 1998 00:00:00 GMT</DATE>
<ASK>0.5967</ASK>
<BID>0.5964</BID>
</CONVERSION>
</RESPONSE>
代码:
XmlDocument doc = new XmlDocument();
doc.Load(xmlUrl);
XmlNode GeneralInformationNode =
doc.SelectSingleNode("/RESPONSE");
foreach (XmlNode node in GeneralInformationNode)
{
var currrates = new Rates();
currrates.Currency_ID =
GeneralInformationNode.SelectSingleNode("EXCH").InnerText;
currrates.Sell_Rate =
GeneralInformationNode.SelectSingleNode("EXPR").InnerText;
Console.WriteLine(currrates.Currency_ID + currrates.Sell_Rate);
Console.ReadKey();
}