我一直难以理解 XPath。
我想做的是从货币国家代码中提取汇率。
我的带有货币的 XML 在这里: http: //www.nationalbanken.dk/dndk/valuta.nsf/valuta.xml
这是我的查询:
query = xml.XPathSelectElement(**"exhangerates/dailyrates/currency[@code='"+ country +"']@rate"**).Value;
我在 .NET 3.5 和一个 asp webservice 项目中工作,这会产生以下错误:
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