The PBDOM_OBJECT class represents any node in an XML node tree and serves as the base class for specialized PBDOM classes that represent specific node types. The DOM class that corresponds to PBDOM_OBJECT is the Node object. PBDOM_OBJECT contains all the basic features required by derived classes. A node can be an element node, a document node, or any of the node types listed above that derive from PBDOM_OBJECT.
The PBDOM_OBJECT base class has the following methods:
AddContent, GetContent, InsertContent, RemoveContent, and SetContent to allow you to manipulate the children of the PBDOM_OBJECT
Clone to allow you to make shallow or deep clones of the PBDOM_OBJECT
Detach to detach the PBDOM_OBJECT from its parent
Equals to test for equality with another PBDOM_OBJECT
GetName and SetName to get and set the name of the PBDOM_OBJECT
GetObjectClass and GetObjectClassString to identify the class of the PBDOM_OBJECT
GetOwnerDocumentObject to identify the owner PBDOM_DOCUMENT of the current PBDOM_OBJECT
GetParentObject and SetParentObject to get and set the parent of the PBDOM_OBJECT
GetText, GetTextNormalize, and GetTextTrim to obtain the text data of the PBDOM_OBJECT
HasChildren to determine whether the PBDOM_OBJECT has any children
IsAncestorObjectOf to determine whether the PBDOM_OBJECT is the ancestor of another PBDOM_OBJECT
The PBDOM_OBJECT class is similar to a virtual class in C++ in that it is not expected to be directly instantiated and used. For example, although a PBDOM_OBJECT can be created using the PowerScript CREATE statement, its methods cannot be used directly:
PBDOM_OBJECT pbdom_obj pbdom_obj = CREATE PBDOM_OBJECT pbdom_obj.SetName("VIRTUAL_PBDOM_OBJ") //exception!
The third line of code above throws an exception because it attempts to directly access the SetName method for the base class PBDOM_OBJECT. A similar implementation is valid, however, when the SetName method is accessed from a derived class, such as PBDOM_ELEMENT:
PBDOM_OBJECT pbdom_obj pbdom_obj = CREATE PBDOM_ELEMENT pbdom_obj.SetName ("VIRTUAL_PBDOM_OBJ")
The PBDOM_OBJECT class can be used as a placeholder for an object of a derived class:
PBDOM_DOCUMENT pbdom_doc PBDOM_OBJECT pbdom_obj pbdom_doc = CREATE PBDOM_DOCUMENT pbdom_doc.NewDocument ("", "", & "Root_Element_From_Doc_1", "", "") pbdom_obj = pbdom_doc.GetRootElement pbdom_obj.SetName & ("Root_Element_From_Doc_1_Now_Changed")
The instantiated PBDOM_OBJECT pbdom_obj is assigned to a PBDOM_DOCUMENT object, which holds the return value of the GetRootElement method. Here, pbdom_obj holds a reference to a PBDOM_ELEMENT and can be operated on legally like any object of a class derived from PBDOM_OBJECT.
A PBDOM_OBJECT can be created as a self-contained object independent of any document or parent PBDOM_OBJECT. Such a PBDOM_OBJECT is known as a standalone object. For example:
PBDOM_ELEMENT pbdom_elem_1 pbdom_elem_1 = Create PBDOM_ELEMENT pbdom_elem_1.SetName("pbdom_elem_1")
pbdom_elem_1 is instantiated in the derived class PBDOM_ELEMENT using the Create keyword. The SetName method can then be invoked from the pbdom_elem_1 object, which is a standalone object not contained within any document.Standalone objects can perform any legal PBDOM operations, but standalone status does not give the object any special advantages or disadvantages.
A PBDOM_OBJECT can be assigned a parent by appending it to another standalone PBDOM_OBJECT, as in the following example:
PBDOM_ELEMENT pbdom_elem_1 PBDOM_ELEMENT pbdom_elem_2 pbdom_elem_1 = Create PBDOM_ELEMENT pbdom_elem_2 = Create PBDOM_ELEMENT pbdom_elem_1.SetName("pbdom_elem_1") pbdom_elem_2.SetName("pbdom_elem_2") pbdom_elem_1.AddContent(pbdom_elem_2)
Two PBDOM_ELEMENT objects, pbdom_elem_1 and pbdom_elem_2, are instantiated. The pbdom_elem_2 object is appended as a child object of pbdom_elem_1 using the AddContent method. In this example, neither pbdom_elem_1 nor pbdom_elem_2 is owned by any document, and the pbdom_elem_1 object is still standalone. If pbdom_elem_1 were assigned to a parent PBDOM_OBJECT owned by a document, pbdom_elem_1 would cease to be a standalone object.