Manipulating the node-tree hierarchy
You can restructure an XML node tree by rearranging its nodes.
One means of manipulating nodes involves detaching a child node
from its parent node. This can be accomplished with the Detach method,
as in the following example.
The root element of a PBDOM_DOCUMENT object named pbdom_doc is obtained
using the GetRootElement method:
1 |
pbdom_obj = pbdom_doc.GetRootElement() |
The root element is detached from the PBDOM_DOCUMENT
object, which is the parent node of the root element:
1 |
pbdom_obj.Detach() |
PBDOM provides the SetParentObject method
to make an object a child of another object.
Checking for parent node
The GetParentObject method can be used
to determine whether an element has a parent object, as in the following
example:
1 |
pbdom_parent_obj = pbdom_obj.GetParentObject()<br>if not IsValid(pbdom_parent_obj) then<br>   MessageBox ("Invalid", "Root Element has no Parent")<br>end if |
If the object on which GetParentObject is
called has no parent object, the function returns NULL.
PBDOM provides similar methods that return information about
an element’s place in an XML node tree. These methods include HasChildren,
which returns a boolean indicating whether an object has child objects,
and IsAncestorObjectOf, which indicates whether
an object is the ancestor of another object.