This is my xml
<DataSet xmlns="http://www.bnr.ro/xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bnr.ro/xsd nbrfxrates.xsd">
<Header>
<Publisher>National Bank of Romania</Publisher>
<PublishingDate>2016-03-24</PublishingDate>
<MessageType>DR</MessageType>
</Header>
<Body>
<Subject>Reference rates</Subject>
<OrigCurrency>RON</OrigCurrency>
<Cube date="2016-03-24">
<Rate currency="EUR">4.4655</Rate>
</Cube>
<Cube date="2016-03-23">
Rate currency="EUR">4.4641</Rate>
</Cube>
</Body>
</DataSet>
I want to verify the Cube Attribute date to receive the EUR value from yesterday date.
For example if today is 2016-03-24 I want to receive the value 4.4641 from 2016-03-23.
I tried with LINQ to XML
string date_yesterday = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd");
XElement root = XElement.Parse(sbXmlText.ToString());
IEnumerable<XElement> adress =
from el in root.Descendants("Cube")
let z = el.ElementsAfterSelf().FirstOrDefault()
where z != null && (string)el.Attribute("date") == date_yesterday
select el;
foreach (XElement el in adress)
Console.WriteLine(el);
And tried
string date_yesterday = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd");
XElement root = XElement.Parse(sbXmlText.ToString());
IEnumerable<XElement> adress =
root.Descendants("Cube").Where(r => r.Attribute("date").Value == date_yesterday);
foreach (XElement el in adress)
Console.WriteLine(el);
And it returns everytime null