1

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

查询是关于带有参数 routePathOutput=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.

谢谢,卡罗

4

0 回答 0