我有以下 url,它在 c# 中返回我的 XML 响应: http ://www.bnr.ro/files/xml/years/nbrfxrates2017.xml
现在,我想为我的日期检索欧元货币,该日期在我的函数中作为参数出现。我想使用 Linq 但我有一些问题
我的功能:
public static void getXml(String year, String data)
{
WebClient webClient = new WebClient();
string url = "http://www.bnr.ro/files/xml/years/nbrfxrates" + year + ".xml";
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(response.GetResponseStream());
XElement xe = XElement.Load(response.GetResponseStream());
var x = (from e in xe.Elements("Cube")
where e.Attribute("date").Value.Equals(data)
select e.Element("Rate") into p
where p.Element("currency").Value.Equals(data)
select p.Value);
Console.WriteLine(x.ToString());
}
我的错误是:
XElement xe = XElement.Load(response.GetResponseStream()); 上缺少根元素