Append Syntax 1
Description
Appends an input string to the text content that already exists
within the current PBDOM_CHARACTERDATA object.
Syntax
|
1 |
pbdom_text_name.Append(string strAppend) |
|
Argument |
Description |
|---|---|
|
pbdom_text_name |
The name of a PBDOM_CHARACTERDATA |
|
strAppend |
The string you want appended to the existing text |
Return value
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 2 3 4 5 6 7 8 9 10 11 12 |
<abc> <data> <child_1> My Text </child_1> <child_2> <!--My Comment--> </child_2> <child_3> <![CDATA[My CDATA]]> </child_3> </data> </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 the child PBDOM_TEXT of child_1 does 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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
PBDOM_Builder pbdombuilder_new pbdom_document pbdom_doc PBDOM_CHARACTERDATA pbdom_chardata_array[] 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>" TRY pbdombuilder_new = Create PBDOM_Builder pbdom_doc = pbdombuilder_new.BuildFromString (strXML) // obtain the child PBDOM_TEXT of child_1 pbdom_doc.GetRootElement().GetChildElement("data").& GetChildElement("child_1"). & GetContent(pbdom_chardata_array) // append the string "Now Appended" to the text // returned by the call to GetContent pbdom_chardata_array[1].Append (" Now Appended") // repeat for child_2 and child_3 pbdom_doc.GetRootElement().GetChildElement("data").& GetChildElement("child_2"). & GetContent(pbdom_chardata_array) pbdom_chardata_array[1].Append (" Now Appended") pbdom_doc.GetRootElement().GetChildElement("data").& GetChildElement("child_3"). & GetContent(pbdom_chardata_array) pbdom_chardata_array[1].Append (" Now Appended") // save pbdom_doc to a file pbdom_doc.SaveDocument ("c:pbdom_doc_1.xml") Destroy pbdombuilder_new CATCH (PBDOM_Exception except) MessageBox ("Exception Occurred", except.Text) END TRY |
The saved file contains the following:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<abc> <data> <child_1> My Text Now Appended </child_1> <child_2> <!--My Comment Now Appended--> </child_2> <child_3> <![CDATA[My CDATA Now Appended]]> </child_3> </data> </abc> |