InsertContent

Description

Inserts a PBDOM_OBJECT as a child of the PBDOM_ATTRIBUTE at a position specified by a referenced PBDOM_OBJECT.

Syntax

pbdom_attribute_name.InsertContent(pbdom_object pbdom_object_new, pbdom_object pbdom_object_ref)

Argument

Description

pbdom_attribute_name

The name of the PBDOM_ATTRIBUTE

pbdom_object_new

The PBDOM_OBJECT to be inserted

pbdom_object_ref

A positional reference to a PBDOM_OBJECT before which pbdom_object_new is to be inserted


Return value

PBDOM_OBJECT. The PBDOM_ATTRIBUTE returned as a PBDOM_OBJECT.

Throws

EXCEPTION_USE_OF_UNNAMED_PBDOM_OBJECT -- The PBDOM_OBJECT to be inserted is nameable and has not been given a user-defined name.

EXCEPTION_PBDOM_OBJECT_ALREADY_HAS_PARENT -- The PBDOM_OBJECT to be inserted already has a parent.

EXCEPTION_INAPPROPRIATE_USE_OF_PBDOM_OBJECT -- The PBDOM_OBJECT to be inserted is not valid to be inserted as a child of this PBDOM_ATTRIBUTE.

EXCEPTION_WRONG_PARENT_ERROR -- The reference PBDOM_OBJECT is not a child of this PBDOM_ATTRIBUTE.

Examples

This example adds an attribute to the root element with the name my_attr and text content "attribute text". It then creates a PBDOM_ENTITYREFERENCE object named ent_ref and inserts it before the attribute's current content. Testing the new content of the attribute should return "&ent_ref;attribute text";

Consider the following code :


PBDOM_DOCUMENT          pbdom_doc
PBDOM_ATTRIBUTE         pbdom_attr
PBDOM_ENTITYREFERENCE   pbdom_entref
PBDOM_OBJECT            pbdom_obj_array[]

try
  pbdom_doc = Create PBDOM_DOCUMENT
  pbdom_entref = Create PBDOM_ENTITYREFERENCE

  // Create a new document object.
  pbdom_doc.NewDocument ("root")
  // Add an attribute "my_attr" to the root element.
  pbdom_doc.GetRootElement().SetAttribute("my_attr", &
     "attribute text")
  // Set the name of the PBDOM_ENTITYREFERENCE.
  pbdom_entref.SetName ("ent_ref")
  
  // Get the existing contents of my_attr
  pbdom_doc.GetRootElement().GetAttribute("my_attr").&
     GetContent(pbdom_obj_array)

// Insert the entity reference to the root element's
// my_attr attribute before the attribute text.
  pbdom_doc.GetRootElement().GetAttribute("my_attr").&
     InsertContent(pbdom_entref, pbdom_obj_array[1])

  // Test the text contents of "my_attr"
  if pbdom_doc.GetRootElement(). &
     GetAttribute("my_attr").GetText() = &
     "&ent_ref;attribute text" then
     MessageBox ("Pass", &
        "GetText() on my_attr is correct.")
  else
    MessageBox ("Fail", &
        "GetText() on my_attr is incorrect.")
  end if

  
catch (pbdom_exception pbdom_except)
  MessageBox ("PBDOM_EXCEPTION", &
     pbdom_except.GetMessage())
end try

Usage

This method inserts the input PBDOM_OBJECT as a child at a specific position (before the reference PBDOM_OBJECT). Currently, only a PBDOM_TEXT and a PBDOM_ENTITYREFERENCE object can be inserted as a child of a PBDOM_ATTRIBUTE.

If the reference PBDOM_OBJECT is null, the PBDOM_OBJECT to be inserted is inserted at the end of this PBDOM_ATTRIBUTE object's list of children.

See also

AddContent

GetContent

RemoveContent

SetContent