internal static XmlNodeList SelectNodes( XmlNode rootNode, XmlNode currentParentNode, string pathDescriptor) { switch (pathDescriptor[0]) { case '*': if (pathDescriptor.Length == 1) { return(PathDescriptorParser.SelectAllChildren(currentParentNode)); } PathDescriptorParser.OnInvalidExpression(pathDescriptor); return((XmlNodeList)null); case '/': return(PathDescriptorParser.SelectAbsoluteNodes(rootNode, pathDescriptor)); case '@': if (pathDescriptor.Length < 2) { PathDescriptorParser.OnInvalidExpression(pathDescriptor); } return(pathDescriptor[1] == '*' ? PathDescriptorParser.SelectAllAttributes(currentParentNode) : PathDescriptorParser.SelectAttributes(currentParentNode, pathDescriptor)); default: return(PathDescriptorParser.SelectChildNodes(currentParentNode, pathDescriptor, 0)); } }
private static XmlNodeList SelectAbsoluteNodes(XmlNode rootNode, string path) { var pos = 1; var xmlNode = rootNode; int startPos; while (true) { startPos = pos; var childNodes = xmlNode.ChildNodes; var num = PathDescriptorParser.ReadPosition(path, ref pos); if (pos == path.Length || path[pos] == '/') { if (childNodes.Count == 0 || num < 0 || num > childNodes.Count) { PathDescriptorParser.OnNoMatchingNode(path); } xmlNode = childNodes.Item(num - 1); if (pos != path.Length) { ++pos; } else { break; } } else if (path[pos] != '-' && path[pos] != '|') { PathDescriptorParser.OnInvalidExpression(path); } else { goto label_8; } } var xmlPatchNodeList = (XmlPatchNodeList) new SingleNodeList(); xmlPatchNodeList.AddNode(xmlNode); return((XmlNodeList)xmlPatchNodeList); label_8: return(PathDescriptorParser.SelectChildNodes(xmlNode, path, startPos)); }