PBDOM_CHARACTERDATA:
Clone method
Description
Creates
and returns a clone of the current PBDOM_CHARACTERDATA.
Syntax
1 |
<span>pbdom_chardata_name</span>.Clone(boolean <span>bDeep</span>) |
Argument |
Description |
---|---|
pbdom_chardata_name |
The name of a PBDOM_CHARACTERDATA. |
bDeep |
A boolean specifying whether a deep or |
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:
1 |
<abc><br>   <data>Data</data><br></abc> |
The PowerScript code obtains the data element of the root
element as a PBDM_ELEMENT and obtains an array of its children.
The array has only one item, the PBDOM_TEXT containing
the string “data”:
1 |
PBDOM_BUILDER pbdombuilder_new<br>PBDOM_DOCUMENT pbdom_doc<br>PBDOM_ELEMENT pbdom_elem<br>PBDOM_CHARACTERDATA pbdom_chardata_1<br>PBDOM_CHARACTERDATA pbdom_chardata_2<br>PBDOM_CHARACTERDATA pbdom_chardata_3<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>// get the data element, store in pbdom_elem,<br>// and get an array of its children<br>   pbdom_elem = pbdom_doc.GetRootElement(). &<br>      GetChildElement("data")<br>   pbdom_elem.GetContent(pbdom_obj_array) |
This PBDOM_TEXT is assigned into a PBDOM_CHARACTERDATA object, pbdom_chardata_1.
Calling GetObjectClassString on pbdom_chardata_1 returns
the class name of the actual object contained within it, pbdom_text
. Calling GetText on
it returns the string Data:
1 |
   pbdom_chardata_1 = pbdom_obj_array[1]<br>   MessageBox ("Class", &<br>      pbdom_chardata_1.GetObjectClassString())<br>   MessageBox ("Text", pbdom_chardata_1.GetText()) |
Calling Clone on pbdom_chardata_1 creates
a new PBDOM_CHARACTERDATA object. However, because the
actual object referenced by pbdom_chardata_1 is
a PBDOM_TEXT, the clone is a PBDOM_TEXT object.Calling GetObjectClassString and GetText on
the clone have the same result as for pbdom_chardata_1.
The clone and the original object are separate objects and a call
to Equals returns false:
1 |
   pbdom_chardata_2 = pbdom_chardata_1.Clone(TRUE)<br>   MessageBox ("Class", &<br>      pbdom_chardata_2.GetObjectClassString())<br>   MessageBox ("Text", pbdom_chardata_2.GetText())<br>   if (pbdom_chardata_1.Equals(pbdom_chardata_2)) then<br>     MessageBox ("Equals", &<br>        "pbdom_chardata_1 equals pbdom_chardata_2")<br>   else<br>     MessageBox ("Equals", &<br>       "pbdom_chardata_1 NOT equals pbdom_chardata_2")<br>   end if |
However, a call to Equals returns true if
the object being compared to pbdom_chardata_1 is
a reference to pbdom_chardata_1:
1 |
   pbdom_chardata_3 = pbdom_chardata_1<br>   if (pbdom_chardata_1.Equals(pbdom_chardata_3)) then<br>     MessageBox ("Equals", &<br>        "pbdom_chardata_1 equals pbdom_chardata_3")<br>   else<br>     MessageBox ("Equals", &<br>        "pbdom_chardata_1 NOT equals pbdom_chardata_3")<br>   end if<br> <br>   DESTROY pbdombuilder_new<br> <br>CATCH (PBDOM_Exception except)<br>   MessageBox ("Exception Occurred", except.Text)<br>END TRY |
Usage
The Clone method creates a new PBDOM_CHARACTERDATA
object which is a duplicate of, and a separate object from, the
original. Calling Equals using these two objects
returns false.
The clone of a PBDOM_CHARACTERDATA object is always
identical to its original whether bDeep is true or false, because
a PBDOM_CHARACTERDATA object contains no subtree of child PBDOM_OBJECTs.A
PBDOM_CHARACTERDATA clone has no parent, but it resides
in the same PBDOM_DOCUMENT as its original, and if the
original PBDOM_CHARACTERDATA is standalone, the clone is
standalone.