我正在尝试处理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.
谢谢, 卡罗