I am not 100% sure which nodes you expect here, but based on what you tried to write, I tried to replicate in a scalable way.
Basically you will need to use the contents of the array to create the correct XPath. Here I have some functions that will help change these exception lists into the corresponding XPath condition. Personally, I use LINQ and string.Join() to make this a lot easier to write and manage.
// supporting methods to build parts of the string static string ElementNotInList<T>(string element, params T[] list) { return String.Join(" and ", list.Select(x => String.Concat(element, "!=", x))); } static string ElementInList<T>(string element, params T[] list) { return String.Join(" or ", list.Select(x => String.Concat(element, "=", x))); } var excludeSubmenus = new[] { 2905, 323 }; var xpath = String.Join("|", String.Format("//Menu[{0}]/Item[ItemLevel={1} and ItemType!='Javascript']", ElementNotInList("MenuId", excludeSubmenus), iLevel), String.Format("//Menu[{0}]/Item[ItemLevel={1} and ItemType='content']", ElementInList("MenuId", excludeSubmenus), iLevel) ); var nextLevelNodeList = currentNode.SelectNodes(xpath);
Jeff mercado
source share