private static NodeList ApplySelection(NodeList nodeList, string xpath) { Guard.ArgumentNotNullOrEmpty(xpath, "xpath"); if (xpath[0] == '/') { throw new ArgumentException("XPath expressions starting with '/' are not supported", "xpath"); } if (xpath.IndexOf("//") >= 0) { throw new ArgumentException("XPath expressions with '//' are not supported", "xpath"); } string head = xpath; string tail = null; int slash = xpath.IndexOf('/'); if (slash >= 0) { head = xpath.Substring(0, slash); tail = xpath.Substring(slash + 1); } NodeList resultNodes = new NodeList(); NodeFilter filter = new NodeFilter(head); foreach (XmlNode node in nodeList) { foreach (XmlNode childNode in node.ChildNodes) { if (filter.Pass(childNode)) { resultNodes.Add(childNode); } } } return(tail != null ? ApplySelection(resultNodes, tail) : resultNodes); }