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; }
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); } }