c# – 使用xPath循环遍历项目
发布时间:2020-12-15 23:52:22 所属栏目:百科 来源:网络整理
导读:我试着循环一个xml文档,我仍然在第二次迭代中得到第一个元素,不知道我错过了什么.有人可以帮忙吗? Xpath很新 string file = HttpContext.Current.Server.MapPath("~/XML/Locations.xml"); Dictionarystring,Location locationCollection = new Dictionaryst
我试着循环一个xml文档,我仍然在第二次迭代中得到第一个元素,不知道我错过了什么.有人可以帮忙吗? Xpath很新
string file = HttpContext.Current.Server.MapPath("~/XML/Locations.xml"); Dictionary<string,Location> locationCollection = new Dictionary<string,Location>(); XPathDocument xDocument = new XPathDocument(file); XPathNavigator xPathNavigator = xDocument.CreateNavigator(); foreach (XPathNavigator node in xPathNavigator.Select("//locations/*")) { string value = node.SelectSingleNode("/locations/location/cell").Value; } <?xml version="1.0" encoding="utf-8" ?> <locations> <location> <locationName>Glendale</locationName> <street>3717 San Fernando Road</street> <city>Glendale</city> <state>CA</state> <zipcode>91204</zipcode> <generalManager>DJ Eldon</generalManager> <phone>(818) 552 |