PBDOM_CHARACTERDATA:
Append Syntax 1 method
Description
Appends
an input string to the text content that already exists within the
current PBDOM_CHARACTERDATA object.
Syntax
1 |
<span>pbdom_text_name</span>.Append(string <span>strAppend</span><span></span>) |
Argument |
Description |
---|---|
pbdom_text_name |
The name of a PBDOM_CHARACTERDATA |
strAppend |
The string you want appended to the existing |
Return Values
PBDOM_CHARACTERDATA. The current PBDOM_CHARACTERDATA modified
and returned as a PBDOM_CHARACTERDATA object.
Throws
EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE – If
this PBDOM_CHARACTERDATA object is not a reference to an
object derived from PBDOM_CHARACTERDATA.
Examples
In this example, the PowerScript code builds a PBDOM_DOCUMENT
based on the following DOM Tree:
1 |
<abc><br>   <data><br>      <child_1><br>         My Text<br>      </child_1><br>      <child_2><br>        <!--My Comment--><br>      </child_2><br>      <child_3><br>         <![CDATA[My CDATA]]><br>      </child_3><br>   </data><br></abc> |
The root element abc has a child element, data,
that has three child elements. child_1 contains
a child PBDOM_TEXT with the string “My Text”. child_2 contains
a child PBDOM_COMMENT with the string “My Comment”. child_3 contains
a child PBDOM_CDATA with the string “My CDATA”.
In the following PowerScript code, the single statement that
follows the comment // obtain
does
the child PBDOM_TEXT of child_1
the following:
-
Obtains the
root element of the PBDOM_DOCUMENT pbdom_doc using GetRootElement.
A new PBDOM_ELEMENT representing the root element abc is
created in memory and returned. -
Calls the GetChildElement method
on the returned root abc PBDOM_ELEMENT
using data as the parameter to single out the data child element.
A PBDOM_ELEMENT representing the data element is created
in memory and returned. -
Calls the GetChildElement on
the returned data PBDOM_ELEMENT, using child_1 as
the parameter to single out the child_1 child
element. A PBDOM_ELEMENT representing the child_1 element
is created in memory and returned. -
Calls the GetContent method on
the returned child_1 PBDOM_ELEMENT,
supplying a reference to the unbounded array pbdom_chardata_array.You can supply PBDOM_CHARACTERDATA array instead
of a PBDOM_OBJECT array because PBDOM_CHARACTERDATA
is a subclass of PBDOM_OBJECT. However, GetContent fails
if child_1 contains any objects other than PBDOM_CHARACTERDATA
objects.
Because child_1 holds only the
PBDOM_TEXT containing the string “My Text”,
this statement returns an array that has only one array item. The
next statement appends another string to the array item. The example
then repeats these steps for child_2 and child_3 and
saves pbdom_doc to a file:
1 |
PBDOM_Builder          pbdombuilder_new<br>pbdom_document         pbdom_doc<br>PBDOM_CHARACTERDATA    pbdom_chardata_array[]<br> <br>string strXML = "<abc><data><child_1>My Text</child_1><child_2><!--My Comment--></child_2><child_3><![CDATA[My CDATA]]></child_3></data></abc>"<br> <br>TRY<br>  pbdombuilder_new = Create PBDOM_Builder<br>  pbdom_doc = pbdombuilder_new.BuildFromString (strXML) |
1 |
<br>// obtain the child PBDOM_TEXT of child_1 <br>  pbdom_doc.GetRootElement().GetChildElement("data").&<br>    GetChildElement("child_1"). &<br>    GetContent(pbdom_chardata_array)<br> <br>// append the string "Now Appended" to the text <br>// returned by the call to GetContent<br>  pbdom_chardata_array[1].Append (" Now Appended")<br> <br>// repeat for child_2 and child_3<br>  pbdom_doc.GetRootElement().GetChildElement("data").&<br>    GetChildElement("child_2"). &<br>    GetContent(pbdom_chardata_array)<br>  pbdom_chardata_array[1].Append (" Now Appended")<br> <br>  pbdom_doc.GetRootElement().GetChildElement("data").&<br>    GetChildElement("child_3"). &<br>    GetContent(pbdom_chardata_array)<br>  pbdom_chardata_array[1].Append (" Now Appended")<br> <br>// save pbdom_doc to a file<br>  pbdom_doc.SaveDocument ("c:pbdom_doc_1.xml")<br> <br>  Destroy pbdombuilder_new<br> <br>CATCH (PBDOM_Exception except)<br>  MessageBox ("Exception Occurred", except.Text)<br>END TRY |
The saved file contains the following:
1 |
<abc><br>   <data><br>      <child_1><br>         My Text Now Appended<br>      </child_1><br>      <child_2><br>        <!--My Comment Now Appended--><br>      </child_2><br>      <child_3><br>         <![CDATA[My CDATA Now Appended]]><br>      </child_3><br>   </data><br></abc> |