예제 #1
0
        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));
            }
        }
예제 #2
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));
        }
예제 #3
0
        private static XmlNodeList SelectAttributes(XmlNode parentNode, string path)
        {
            var pos              = 1;
            var attributes       = parentNode.Attributes;
            var xmlPatchNodeList = (XmlPatchNodeList)null;

            while (true)
            {
                var name = PathDescriptorParser.ReadAttrName(path, ref pos);
                if (xmlPatchNodeList == null)
                {
                    xmlPatchNodeList = pos != path.Length ? (XmlPatchNodeList) new MultiNodeList() : (XmlPatchNodeList) new SingleNodeList();
                }
                var namedItem = attributes.GetNamedItem(name);
                if (namedItem == null)
                {
                    PathDescriptorParser.OnNoMatchingNode(path);
                }
                xmlPatchNodeList.AddNode(namedItem);
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        ++pos;
                        if (path[pos] != '@')
                        {
                            PathDescriptorParser.OnInvalidExpression(path);
                        }
                        ++pos;
                    }
                    else
                    {
                        PathDescriptorParser.OnInvalidExpression(path);
                    }
                }
                else
                {
                    break;
                }
            }
            return((XmlNodeList)xmlPatchNodeList);
        }
예제 #4
0
        private static XmlNodeList SelectChildNodes(
            XmlNode parentNode,
            string path,
            int startPos)
        {
            var pos              = startPos;
            var childNodes       = parentNode.ChildNodes;
            var num1             = PathDescriptorParser.ReadPosition(path, ref pos);
            var xmlPatchNodeList = pos != path.Length ? (XmlPatchNodeList) new MultiNodeList() : (XmlPatchNodeList) new SingleNodeList();

            while (true)
            {
                if (num1 <= 0 || num1 > childNodes.Count)
                {
                    PathDescriptorParser.OnNoMatchingNode(path);
                }
                var node = childNodes.Item(num1 - 1);
                xmlPatchNodeList.AddNode(node);
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        ++pos;
                    }
                    else if (path[pos] == '-')
                    {
                        ++pos;
                        var num2 = PathDescriptorParser.ReadPosition(path, ref pos);
                        if (num2 <= 0 || num2 > childNodes.Count)
                        {
                            PathDescriptorParser.OnNoMatchingNode(path);
                        }
                        while (num1 < num2)
                        {
                            ++num1;
                            node = node.NextSibling;
                            xmlPatchNodeList.AddNode(node);
                        }
                        if (pos != path.Length)
                        {
                            if (path[pos] == '|')
                            {
                                ++pos;
                            }
                            else
                            {
                                PathDescriptorParser.OnInvalidExpression(path);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    num1 = PathDescriptorParser.ReadPosition(path, ref pos);
                }
                else
                {
                    break;
                }
            }
            return((XmlNodeList)xmlPatchNodeList);
        }