I want to retrieve the currency value from National Bank XML. The XML contains the value for EUR for 10 days. I want to take the EUR value from the previous date.
For example if today is 2016-03-23 I want the EUR value from 2016-03-22.
I am using XPath for Parsing the XML. How can I verify an attribute using a string ?
First I tried parsing XML with XPathExpression .
XmlDocument XML_De_La_BNR = new XmlDocument();
XML_De_La_BNR.LoadXml(sbXmlText.ToString());
XPathNavigator Navigator_Prin_XML = XML_De_La_BNR.CreateNavigator();
XmlNamespaceManager Manager_Spatii_De_Nume = new XmlNamespaceManager(Navigator_Prin_XML.NameTable);
Manager_Spatii_De_Nume.AddNamespace("BNR", "http://www.bnr.ro/xsd");
string date_yesterday = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd");
XPathExpression Interogare_XPath_Date = Navigator_Prin_XML.Compile("/BNR:DataSet/BNR:Body/BNR:Cube[@date='date_yesterday']/BNR:Rate[@currency='EUR']");
Interogare_XPath_Date.SetContext(Manager_Spatii_De_Nume);
XPathNavigator Nod_Rata_Date = Navigator_Prin_XML.SelectSingleNode(Interogare_XPath_Date);
Second method , I tried with a foreach where I look for every 'Cube' note and retrieve a date. And after I will have an if condition if that date is equal with mydate retrieve EUR value.
List<string> dates = new List<string>();
foreach (XmlNode node in XML_De_La_BNR.GetElementsByTagName("Cube"))
{
XmlNode date_y = node["date"];
dates.Add(date_y.InnerText);
}