具有命名空间的SelectNodes返回太多事件

时间:2012-11-24 23:31:38

标签: c# xml-namespaces xmldocument bing-api

我正在尝试处理Bing Maps REST Routes API的响应。

查询是关于带参数routePathOutput = Point的驾驶路线(即返回路线路径的Point(经度和纬度)值列表)。

我需要在RoutePath子树中仅选择“纬度”和“经度”元素,但SelectNodes方法会返回XmlDocument中的所有“纬度”和“经度”。

XmlNamespaceManager nsmgr = new XmlNamespaceManager(routeResponse.NameTable);
nsmgr.AddNamespace("rest", "http://schemas.microsoft.com/search/local/ws/rest/v1");

// This works fine:
XmlNodeList pathList = routeResponse.SelectNodes("//rest:RoutePath", nsmgr);
// ... and now pathList.Count = 1

// This doesn't work as I expected:
XmlNodeList latitudeList = pathList[0].SelectNodes("//rest:Latitude", nsmgr);
// ... because latitudeList contains all the occurrences of the element 'Latitude' in the  XmlDocument,
// not only the once in the 'RoutePath' subtree.

谢谢, 卡罗

0 个答案:

没有答案
相关问题