+ }\r
+\r
+treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode ancestor_closing)\r
+ {\r
+\r
+ NULLT_IF(x==NULLT || x==Root());\r
+\r
+ treeNode close = fast_find_close(Par,x);\r
+ treeNode ns = close+1;\r
+ if ( (fast_inspect(Par,ns) == OP) && (tags->find(Tag(ns)) != tags->end()))\r
+ return ns;\r
+\r
+ int i;\r
+ treeNode min = NULLT;\r
+ treeNode aux;\r
+ \r
+\r
+ TagIdSet::const_iterator tagit;\r
+ for (tagit = tags->begin(); tagit != tags->end(); ++tagit) {\r
+\r
+ aux = tagpos2node(Tags->select_next(*tagit, close));\r
+ if (aux == NULLT) continue;\r
+ if ((min == NULLT) || (aux < min)) min = aux;\r
+ };\r
+ \r
+ // found the smallest node in preorder which is after x.\r
+ // if ctx is the root node, just return what we found.\r
+\r
+ if (ancestor_closing == Root() || min == NULLT || min < ancestor_closing) return min;\r
+ else return NULLT;\r