加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读