I’ve been having some trouble getting my head around XPath.
Want i want to do, is to extract an exchange rate from a currency country code.
My XML with currecies is here: http://www.nationalbanken.dk/dndk/valuta.nsf/valuta.xml
This is my query:
query = xml.XPathSelectElement(**"exhangerates/dailyrates/currency[@code='"+ country +"']@rate"**).Value;
I’m workiing in .NET 3.5 and a asp webservice project, which produces the following error:
System.Xml.XPath.XPathException: 'exhangerates/dailyrates/currency[@code='USD']@rate' has an invalid token.
at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)
at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey)
at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean& needContext)
at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
at System.Xml.XPath.XPathNavigator.Evaluate(String xpath, IXmlNamespaceResolver resolver)
at System.Xml.XPath.XPathEvaluator.Evaluate[T](XNode node, String expression, IXmlNamespaceResolver resolver)
at System.Xml.XPath.Extensions.XPathSelectElements(XNode node, String expression, IXmlNamespaceResolver resolver)
at System.Xml.XPath.Extensions.XPathSelectElement(XNode node, String expression)
at WebServiceCurrency.Service1.RetrieveExchangeRate(String country) in c:\Users\Peter\Documents\GitHub\HotMess\C#\Webservices\WebServiceCurrency\WebServiceCurrency\Service1.asmx.cs:line 35
This works:
Output:
So the solution for you should be