Esempio n. 1
0
 public override bool MoveNextCore()
 {
     while (_iter.MoveNext())
     {
         if (_test.Match(NamespaceManager, _iter.Current))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
        public virtual bool Matches(XPathExpression expr)
        {
            Expression e = ((CompiledExpression)expr).ExpressionNode;

            if (e is ExprRoot)
            {
                return(NodeType == XPathNodeType.Root);
            }

            NodeTest nt = e as NodeTest;

            if (nt != null)
            {
                switch (nt.Axis.Axis)
                {
                case Axes.Child:
                case Axes.Attribute:
                    break;

                default:
                    throw new XPathException("Only child and attribute pattern are allowed for a pattern.");
                }
                return(nt.Match(((CompiledExpression)expr).NamespaceManager, this));
            }
            if (e is ExprFilter)
            {
                do
                {
                    e = ((ExprFilter)e).LeftHandSide;
                } while (e is ExprFilter);

                if (e is NodeTest && !((NodeTest)e).Match(((CompiledExpression)expr).NamespaceManager, this))
                {
                    return(false);
                }
            }

            XPathResultType resultType = e.ReturnType;

            switch (resultType)
            {
            case XPathResultType.Any:
            case XPathResultType.NodeSet:
                break;

            default:
                return(false);
            }

            switch (e.EvaluatedNodeType)
            {
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                if (NodeType != e.EvaluatedNodeType)
                {
                    return(false);
                }
                break;
            }

            XPathNodeIterator nodes;

            nodes = this.Select(expr);
            while (nodes.MoveNext())
            {
                if (IsSamePosition(nodes.Current))
                {
                    return(true);
                }
            }

            // ancestors might select this node.

            XPathNavigator navigator = Clone();

            while (navigator.MoveToParent())
            {
                nodes = navigator.Select(expr);

                while (nodes.MoveNext())
                {
                    if (IsSamePosition(nodes.Current))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }