代码之家  ›  专栏  ›  技术社区  ›  Younes

从XmlNodeList(Sytem.Xml)中筛选节点。XmlNodeList)

  •  0
  • Younes  · 技术社区  · 14 年前

    XmlNodeList是我从dtSearch中得到的。 该列表包含在指定搜索短语中找到的项的列表。 我想过滤掉所有不属于我想看的网站的项目。

    // Get a list of Item nodes
    XmlNodeList list = xmlResult.SelectNodes("/sitecore/result/item");
    
    foreach (System.Xml.XmlNode node in list)
    { 
    
       XmlNode thisScPath = node.SelectSingleNode("scPath");
       if (thisScPath == null)
         continue;  
    }
    

    假设我想过滤掉包含字符串“xxy”的scPath的所有节点,在我进入foreach之前是否可以这样做,在foreach中我遍历了列表中的所有节点?例如,我可以用Linq做这个吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Richard    14 年前

    您可以将谓词添加到XPath表达式中,例如。

    /sitecore/result/item[scPath!='xxy']
    

    将查找所有没有值为“xxy”的子节点“scPath”的项节点。