Ejemplo n.º 1
0
 public NodeSet CreateNodeSet(object key, XQueryExprBase[] path)
 {
     List<DmNode> nodes = new List<DmNode>();
     GetNodesVisitor(path, this, 0, path.Length, nodes);
     NodeSet res = new NodeSet(nodes);            
     if (_cached_set == null)
         _cached_set = new Dictionary<object, NodeSet>();
     _cached_set.Add(key, res);
     return res;
 }
Ejemplo n.º 2
0
        private void GetNodesVisitor(XQueryExprBase[] path, DmNode curr, int index, int length, List<DmNode> res)
        {
            XQueryStepExpr expr = path[index] as XQueryStepExpr;
            if (expr == null)
                throw new ArgumentException();
            DmNode[] nodes;
            switch (expr.ExprType)
            {
                case XQueryPathExprType.Self:
                    nodes = curr.GetSelf();
                    break;

                case XQueryPathExprType.Child:
                    nodes = curr.GetChilds();
                    break;

                case XQueryPathExprType.Descendant:
                    nodes = curr.GetDescendants();
                    break;

                case XQueryPathExprType.DescendantOrSelf:
                    nodes = curr.GetDescendantOrSelf();
                    break;

                default:
                    throw new ArgumentException();
            }
            foreach (DmNode node in nodes)
                if (node.TestNode(expr.NameTest, expr.TypeTest))
                {
                    if (index < length -1)
                        GetNodesVisitor(path, node, index + 1, length, res);
                    else
                        res.Add(node);
                }
        }