-// FirstChild(x): returns the first child of node x, assuming it exists. Very fast in BP.\r
-/*\r
-treeNode XMLTree::FirstChild(treeNode x) \r
- {\r
- NULLT_IF(x==NULLT);\r
- return fast_first_child(Par, x);\r
- }\r
-*/\r
-/*\r
-treeNode XMLTree::FirstElement(treeNode x) \r
- {\r
- NULLT_IF(x==NULLT);\r
- x = fast_first_child(Par, x);\r
- NULLT_IF(x == NULLT);\r
- switch (Tag(x)){\r
- \r
- case PCDATA_TAG_ID:\r
- x = x+2;\r
- return (fast_inspect(Par,x)==OP)? x : NULLT;\r
- \r
- case ATTRIBUTE_TAG_ID: \r
- x = fast_next_sibling(Par,x);\r
- if (x != NULLT && Tag(x) == PCDATA_TAG_ID){\r
- x = x+2;\r
- return (fast_inspect(Par,x)==OP)? x : NULLT;\r
- } \r
- else return x; \r
- default:\r
- return x;\r
- }\r
- }\r
-*//*\r
-treeNode XMLTree::NextElement(treeNode x) \r
-{\r
- NULLT_IF(x==NULLT);\r
- x = fast_next_sibling(Par, x);\r
- NULLT_IF(x == NULLT); \r
- if (Tag(x) == PCDATA_TAG_ID){\r
- x = x+2;\r
- return (fast_inspect(Par,x)==OP)? x : NULLT;\r
- }\r
- else return x; \r
- }*/\r
-\r
-// LastChild(x): returns the last child of node x.\r
-treeNode XMLTree::LastChild(treeNode x)\r
- {\r
- NULLT_IF(x == NULLT || fast_isleaf(Par,x));\r
- return find_open(Par, fast_find_close(Par, x)-1);\r
- }\r
-\r
-// NextSibling(x): returns the next sibling of node x, assuming it exists.\r
-/*treeNode XMLTree::NextSibling(treeNode x) \r
- {\r
- NULLT_IF(x==NULLT || x == Root() );\r
- x = fast_find_close(Par,x)+1;\r
- return (fast_inspect(Par,x) == CP ? NULLT : x);\r
- }\r
-*/\r
-\r
-// PrevSibling(x): returns the previous sibling of node x, assuming it exists.\r
-treeNode XMLTree::PrevSibling(treeNode x) \r
- {\r
- NULLT_IF(x==NULLT);\r
- return prev_sibling(Par, x);\r
- }\r
-\r
-// TaggedChild(x,tag): returns the first child of node x tagged tag, or NULLT if there is none.\r
-// Because of the balanced-parentheses representation of the tree, this operation is not supported\r
-// efficiently, just iterating among the children of node x until finding the desired child.\r
-treeNode XMLTree::TaggedChild(treeNode x, TagType tag) \r
- {\r
- \r
- NULLT_IF(x==NULLT || fast_isleaf(Par,x));\r
- treeNode child; \r
- child = fast_first_child(Par, x); // starts at first child of node x\r
- if (Tag(child) == tag)\r
- return child;\r
- else\r
- return TaggedFollowingSibling(child,tag);\r
- }\r
-\r
-// TaggedSibling(x,tag): returns the first sibling of node x tagged tag, or NULLT if there is none.\r
-treeNode XMLTree::TaggedFollowingSibling(treeNode x, TagType tag)\r
-{\r
- NULLT_IF(x==NULLT);\r
- treeNode sibling = fast_next_sibling(Par, x);\r
- TagType ctag;\r
- while (sibling != NULLT) {\r
- ctag = Tag(sibling);\r
- if (ctag == tag) // current sibling is labeled with tag of interest\r
- return sibling; \r
- sibling = fast_sibling(Par, sibling, ctag); // OK, let's try with the next sibling\r
- }\r
- return NULLT; // no such sibling was found \r
-}\r