Пример #1
0
        internal static XmlDiffPathNodeList SelectNodes(
            XmlDiffViewParentNode rootNode,
            XmlDiffViewParentNode currentParentNode,
            string xmlDiffPathExpr)
        {
            switch (xmlDiffPathExpr[0])
            {
            case '*':
                if (xmlDiffPathExpr.Length == 1)
                {
                    return(XmlDiffPath.SelectAllChildren(currentParentNode));
                }
                XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr);
                return((XmlDiffPathNodeList)null);

            case '/':
                return(XmlDiffPath.SelectAbsoluteNodes(rootNode, xmlDiffPathExpr));

            case '@':
                if (xmlDiffPathExpr.Length < 2)
                {
                    XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr);
                }
                return(xmlDiffPathExpr[1] == '*' ? XmlDiffPath.SelectAllAttributes((XmlDiffViewElement)currentParentNode) : XmlDiffPath.SelectAttributes((XmlDiffViewElement)currentParentNode, xmlDiffPathExpr));

            default:
                return(XmlDiffPath.SelectChildNodes(currentParentNode, xmlDiffPathExpr, 0));
            }
        }
Пример #2
0
        private static XmlDiffPathNodeList SelectAbsoluteNodes(
            XmlDiffViewParentNode rootNode,
            string path)
        {
            Debug.Assert(path[0] == '/');
            var pos  = 1;
            var node = (XmlDiffViewNode)rootNode;
            int startPos;

            while (true)
            {
                startPos = pos;
                var num = XmlDiffPath.ReadPosition(path, ref pos);
                if (pos == path.Length || path[pos] == '/')
                {
                    if (node.FirstChildNode == null)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    var diffViewParentNode = (XmlDiffViewParentNode)node;
                    if (num <= 0 || num > diffViewParentNode._sourceChildNodesCount)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    node = diffViewParentNode.GetSourceChildNode(num - 1);
                    if (pos != path.Length)
                    {
                        ++pos;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (path[pos] != '-' && path[pos] != '|')
                {
                    XmlDiffPath.OnInvalidExpression(path);
                }
                else
                {
                    goto label_10;
                }
            }
            var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();

            diffPathNodeList.AddNode(node);
            return(diffPathNodeList);

label_10:
            if (node.FirstChildNode == null)
            {
                XmlDiffPath.OnNoMatchingNode(path);
            }
            return(XmlDiffPath.SelectChildNodes((XmlDiffViewParentNode)node, path, startPos));
        }
Пример #3
0
        private static XmlDiffPathNodeList SelectAttributes(
            XmlDiffViewElement parentElement,
            string path)
        {
            Debug.Assert(path[0] == '@');
            var pos = 1;
            var diffPathNodeList = (XmlDiffPathNodeList)null;

            while (true)
            {
                var name = XmlDiffPath.ReadAttrName(path, ref pos);
                if (diffPathNodeList == null)
                {
                    diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                }
                var attribute = parentElement.GetAttribute(name);
                if (attribute == null)
                {
                    XmlDiffPath.OnNoMatchingNode(path);
                }
                diffPathNodeList.AddNode((XmlDiffViewNode)attribute);
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        var index = pos + 1;
                        if (path[index] != '@')
                        {
                            XmlDiffPath.OnInvalidExpression(path);
                        }
                        pos = index + 1;
                    }
                    else
                    {
                        XmlDiffPath.OnInvalidExpression(path);
                    }
                }
                else
                {
                    break;
                }
            }
            return(diffPathNodeList);
        }
Пример #4
0
        private static XmlDiffPathNodeList SelectChildNodes(
            XmlDiffViewParentNode parentNode,
            string path,
            int startPos)
        {
            var pos = startPos;
            XmlDiffPathNodeList diffPathNodeList;

            while (true)
            {
                int num1;
                do
                {
                    num1             = XmlDiffPath.ReadPosition(path, ref pos);
                    diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                    if (num1 <= 0 || num1 > parentNode._sourceChildNodesCount)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1));
                    if (pos != path.Length)
                    {
                        if (path[pos] == '|')
                        {
                            ++pos;
                        }
                    }
                    else
                    {
                        goto label_15;
                    }
                }while (path[pos] != '-');
                ++pos;
                var num2 = XmlDiffPath.ReadPosition(path, ref pos);
                if (num2 <= 0 || num2 > parentNode._sourceChildNodesCount)
                {
                    XmlDiffPath.OnNoMatchingNode(path);
                }
                while (num1 < num2)
                {
                    ++num1;
                    diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1));
                }
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        ++pos;
                    }
                    else
                    {
                        XmlDiffPath.OnInvalidExpression(path);
                    }
                }
                else
                {
                    break;
                }
            }
label_15:
            return(diffPathNodeList);
        }