RemoveContent

Description

Removes the input PBDOM_OBJECT from the PBDOM_ATTRIBUTE.

Syntax

pbdom_attribute_name.RemoveContent(pbdom_object pbdom_object_ref)

Argument

Description

pbdom_attribute_name

The name of the PBDOM_ATTRIBUTE

pbdom_object_ref

The PBDOM_OBJECT child to be removed from this PBDOM_ATTRIBUTE


Return value

Boolean.

Returns true if the content has been successfully removed and false otherwise.

Throws

EXCEPTION_INVALID_ARGUMENT -- The input PBDOM_OBJECT is invalid. This can happen if it has not been initialized properly or is a null object reference.

EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- This PBDOM_ATTRIBUTE object or the input PBDOM_OBJECT is not associated with a derived PBDOM_OBJECT class object.

EXCEPTION_USE_OF_UNNAMED_PBDOM_OBJECT -- This PBDOM_ATTRIBUTE or the PBDOM_OBJECT to be removed is nameable and has not been given a user-defined name.

EXCEPTION_WRONG_DOCUMENT_ERROR -- The input PBDOM_OBJECT is not contained within the same PBDOM_DOCUMENT as this PBDOM_ATTRIBUTE.

EXCEPTION_WRONG_PARENT_ERROR -- The input PBDOM_OBJECT is not a child of the current 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.

At this point, my_attr contains two child PBDOM_OBJECTs: a PBDOM_TEXT containing "attribute text" and a PBDOM_ENTITYREFERENCE named ent_ref. The element looks like this when serialized:

<root my_attr="attribute text&ent_ref;">

A call to GetContent returns an array containing these two PBDOM_OBJECTs. pbdom_obj_array[1] should point to the PBDOM_TEXT. After pbdom_obj_array[1] is removed from my_attr, the element looks like this when serialized: <root my_attr="&ent_ref;">.

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 our PBDOM_ENTITYREFERENCE.  
  pbdom_entref.SetName ("ent_ref")
  
  // Add the entity reference to the root 
  // element's "my_attr" attribute.
  pbdom_doc.GetRootElement(). &
     GetAttribute("my_attr"). AddContent(pbdom_entref)

  // Get the existing contents of "my_attr"
  pbdom_doc.GetRootElement().GetAttribute("my_attr").&
     GetContent(pbdom_obj_array)

  // Remove PBDOM_TEXT object from "my_attr"
  pbdom_doc.GetRootElement().GetAttribute("my_attr").&
     RemoveContent(pbdom_obj_array[1])
  
// Test the text contents of "my_attr  "
  if pbdom_doc.GetRootElement(). &
     GetAttribute("my_attr").GetText() = &
     "&ent_ref;" then
    MessageBox ("Pass", &
      "GetText() on my_attr is correct.")
  else
    MessageBox ("Fail", 
      "GetText() on my_attr is incorrect.")
  end if
  
catch (pbdom_exception pbdom_e)
  MessageBox ("PBDOM_EXCEPTION", pbdom_e.GetMessage())
end try

Usage

The RemoveContent method removes the input PBDOM_OBJECT from this PBDOM_ATTRIBUTE. Currently, only a PBDOM_TEXT and a PBDOM_ENTITYREFERENCE object can be part of the contents of a PBDOM_ATTRIBUTE. Therefore, the input PBDOM_OBJECT must be either a PBDOM_TEXT or a PBDOM_ENTITYREFERENCE object.

See also

AddContent

GetContent

InsertContent

SetContent