Append

Description

The Append method is overloaded:

  • Syntax 1 appends an input string to the text content that already exists within the current PBDOM_CHARACTERDATA object.

  • Syntax 2 appends the text data of a PBDOM_CHARACTERDATA object to the text content that already exists within the current PBDOM_CHARACTERDATA object.

Syntax

For this syntax

See

Append(string strAppend)

Append Syntax 1

Append(pbdom_characterdata pbdom_characterdata_ref)

Append Syntax 2


Append Syntax 1

Description

Appends an input string to the text content that already exists within the current PBDOM_CHARACTERDATA object.

Syntax

pbdom_text_name.Append(string strAppend)

Argument

Description

pbdom_text_name

The name of a PBDOM_CHARACTERDATA object

strAppend

The string you want appended to the existing text of the current PBDOM_CHARACTERDATA object


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:

<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:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

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:

<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>

Append Syntax 2

Description

Appends the text data of a PBDOM_CHARACTERDATA object to the text content that already exists within the current PBDOM_CHARACTERDATA object.

Syntax

pbdom_text_name.Append(pbdom_characterdata pbdom_characterdata_ref)

Argument

Description

pbdom_text_name

The name of a PBDOM_CHARACTERDATA

pbdom_characterdata_ref

The referenced PBDOM_CHARACTERDATA object whose text data is to be appended to the existing text of the current PBDOM_CHARACTERDATA object


Return value

PBDOM_CHARACTERDATA. The current PBDOM_CHARACTERDATA modified and returned as a PBDOM_CHARACTERDATA object.

Throws

EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- If the current PBDOM_CHARACTERDATA or the input PBDOM_CHARACTERDATA is not a reference to an object derived from PBDOM_CHARACTERDATA.

Usage

Note that JDOM does not define an Append method for its CHARACTERDATA class. Because PBDOM implements its Append method in the base PBDOM_CHARACTERDATA class, a PBDOM_TEXT object, a PBDOM_CDATA object, and a PBDOM_TEXT object can append their internal text data to each other because they are all PBDOM_CHARACTERDATA-derived objects.