PBDOM_CHARACTERDATA:
GetParentObject method
Description
The GetParentObject method
returns the parent PBDOM_OBJECT of the current PBDOM_CHARACTERDATA.
Syntax
1 |
<span>pbdom_chardata_name</span>.GetParentObject(<span></span>) |
Argument |
Description |
---|---|
pbdom_chardata_name |
The name of a PBDOM_CHARACTERDATA |
Return Values
PBDOM_OBJECT.
Throws
EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE – If
this PBDOM_CHARACTERDATA is not a reference to an object
derived from PBDOM_CHARACTERDATA.
Examples
This example creates a PBDOM_DOCUMENT based
on the following DOM tree and demonstrates how a PBDOM_CHARACTERDATA
INSTANCE can be detached from its parent:
1 |
<abc><br>   <data>Data</data><br></abc> |
The PowerScript code obtains the root element, uses it to
obtain the child element, and then obtains an array of the child
element’s own children. This array has a single item, the
PBDOM_TEXT object with the text Data. The array can be
cast to a PBDOM_CHARACTERDATA object, because it does not
contain any objects that are not derived from PBDOM_CHARACTERDATA.
The parent of pbdom_chardata_1 is
the data element. The following steps detach it from its parent:
-
Create a PBDOM_COMMENT in the PBDOM_CHARACTERDATA object pbdom_chardata_2 and
assign to it the text “Some Comments”. -
Set pbdom_chardata_2 as
an array item of pbdom_obj_array. -
Call SetContent on the parent
of pbdom_chardata_1 (the data element).
Calling SetContent resets the contents
of data, which can cause its original contents
(including pbdom_chardata_1)
to be removed, depending on what is stored inside pbdom_obj_array.
Because pbdom_obj_array contains
only the newly created PBDOM_COMMENT, pbdom_chardata_2, data will
have only this PBDOM_COMMENT as its child.
pbdom_chardata_1 will
have no parent, because it has been silently detached from it. Calling GetParentObject on
it will return null:
1 |
PBDOM_Builder          pbdombuilder_new<br>pbdom_document         pbdom_doc<br>pbdom_document         pbdom_owner_doc<br>PBDOM_CHARACTERDATA    pbdom_chardata_1<br>PBDOM_CHARACTERDATA    pbdom_chardata_2<br>PBDOM_OBJECT           pbdom_obj_array[]<br>string strXML = "<abc><data>Data</data></abc>"<br> <br>TRY<br> pbdombuilder_new = Create PBDOM_Builder<br> pbdom_doc = pbdombuilder_new.BuildFromString (strXML)<br> <br> pbdom_doc.GetRootElement(). &<br>   GetChildElement("data"). &<br>   GetContent(pbdom_obj_array)<br> <br> pbdom_chardata_1 = pbdom_obj_array[1]<br> <br> pbdom_chardata_2 = Create PBDOM_COMMENT<br> pbdom_chardata_2.SetText ("Some Comments")<br> <br> pbdom_obj_array[1] = pbdom_chardata_2<br> <br> pbdom_chardata_1.GetParentObject(). &<br>    SetContent(pbdom_obj_array)<br> <br> if (IsValid(pbdom_chardata_1.GetParentObject())) then<br>    MessageBox ("Has Parent Object", &<br>      "PBDOMTEXT (~'Data~') has a parent")<br> else<br>    MessageBox ("Has Parent Object", &<br>      "PBDOMTEXT (~'Data~') has NO parent")<br> end if<br> <br> pbdom_doc.SaveDocument("c:pbdom_doc_1.xml")<br> <br> Destroy pbdombuilder_new<br> Destroy pbdom_chardata_2<br> <br>CATCH (PBDOM_Exception except)<br> MessageBox ("Exception Occurred", except.Text)<br>END TRY |
When the resulting PBDOM_DOCUMENT is saved to a file,
it looks like this:
1 |
<abc><br>   <data><br>      <!-- Some Comments --><br>   </data><br></abc> |
Usage
The parent is also an object derived from PBDOM_CHARACTERDATA.
If the PBDOM_OBJECT has no parent, null is
returned.