开发者

Filter nodes out of a XmlNodeList (Sytem.Xml. XmlNodeList)

I need the most efficient way to filter out Nodes from a XmlNodeList. The XmlNodeList is what i get back from dtSearch. The list contains a list of items that are found on a specified searchPhrase. I want to filter out all items that are not belonging to the website i want to look on. The information about what website the result has been found on is stored in the path of the result and I can access it using:

// Get a list of Item nodes
XmlNodeList list = xmlResult.SelectNodes("/sitecore/result/item");

foreach (System.Xml.XmlNo开发者_运维百科de node in list)
{ 

   XmlNode thisScPath = node.SelectSingleNode("scPath");
   if (thisScPath == null)
     continue;  
}

Let's say i want to filter out all Nodes with a scPath containing string "xxy", is it possible to do this before i enter the foreach in which i walk through all the nodes in the list? For example, can I do this with Linq?


You can add predicates to the XPath expression, e.g.

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

will find all item nodes that don't have a child node "scPath" with a value "xxy".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜