Ejemplo n.º 1
0
        public PathExprNode(XPath2Context context, PathStep pathStep)
            : base(context)
        {
            List <PathStep> path = new List <PathStep>();

            for (PathStep curr = pathStep; curr != null; curr = curr.Next)
            {
                if (curr.type == XPath2ExprType.Expr)
                {
                    Add(curr.node);
                }
                path.Add(curr);
            }
            if (path.Count == 2 &&
                path[0].type == XPath2ExprType.DescendantOrSelf &&
                path[0].nodeTest == SequenceType.Node &&
                path[1].type == XPath2ExprType.Child)
            {
                _path = new PathStep[] { new PathStep(path[1].nodeTest, XPath2ExprType.Descendant) }
            }
            ;
            else
            {
                bool transform;
                do
                {
                    transform = false;
                    for (int k = 0; k < path.Count - 2; k++)
                    {
                        if (path[k].type == XPath2ExprType.DescendantOrSelf)
                        {
                            int s = k + 1;
                            List <ChildOverDescendantsNodeIterator.NodeTest> nodeTest =
                                new List <ChildOverDescendantsNodeIterator.NodeTest>();
                            for (; s < path.Count; s++)
                            {
                                if (path[s].type != XPath2ExprType.Child)
                                {
                                    break;
                                }
                                nodeTest.Add(new ChildOverDescendantsNodeIterator.NodeTest(path[s].nodeTest));
                            }
                            if (nodeTest.Count > 1)
                            {
                                int n = nodeTest.Count + 1;
                                while (n-- > 0)
                                {
                                    path.RemoveAt(k);
                                }
                                path.Insert(k, new PathStep(nodeTest.ToArray(), XPath2ExprType.ChildOverDescendants));
                                transform = true;
                                break;
                            }
                        }
                    }
                } while (transform);
                _path = path.ToArray();
            }
        }
Ejemplo n.º 2
0
        public void AddLast(PathStep pathStep)
        {
            PathStep last = this;

            while (last.Next != null)
            {
                last = last.Next;
            }
            last.Next = pathStep;
        }
Ejemplo n.º 3
0
        public static AbstractNode Create(XPath2Context context, object value)
        {
            PathStep pathStep = value as PathStep;

            if (pathStep != null)
            {
                return(new PathExprNode(context, pathStep));
            }
            AbstractNode node = value as AbstractNode;

            if (node == null)
            {
                node = new ValueNode(context, value);
            }
            return(node);
        }
Ejemplo n.º 4
0
        public static PathStep Create(XPath2Context context, object node)
        {
            PathStep res = node as PathStep;

            if (res != null)
            {
                return(res);
            }
            PathExprNode pathExpr = node as PathExprNode;

            if (pathExpr != null)
            {
                return(pathExpr.FirstStep);
            }
            return(new PathStep(AbstractNode.Create(context, node)));
        }
Ejemplo n.º 5
0
        public static PathStep CreateFilter(XPath2Context context, object node, List <Object> predicateList)
        {
            if (predicateList.Count == 1)
            {
                AbstractNode predicate = AbstractNode.Create(context, predicateList[0]);
                ValueNode    numexpr   = predicate as ValueNode;
                if (numexpr != null && numexpr.Content is Integer)
                {
                    PathStep res = Create(context, node);
                    res.AddLast(new PathStep(numexpr.Content, XPath2ExprType.PositionFilter));
                    return(res);
                }
            }
            AbstractNode filterExpr = new FilterExprNode(context, node, predicateList);

            return(new PathStep(filterExpr));
        }