Clone

Description

Creates and returns a clone of the current PBDOM_CDATA.

Syntax

pbdom_cdata_name.Clone(boolean bDeep)

Argument

Description

pbdom_cdata_name

The name of a PBDOM_CDATA.

bDeep

A boolean specifying whether a deep or shallow clone is returned. Values are true for a deep clone and false for a shallow clone. This argument is currently ignored.


Return value

PBDOM_OBJECT. The return value is a clone of the current PBDOM_CDATA housed in a PBDOM_OBJECT.

Examples

This example tests the following characteristics of a cloned PBDOM_CDATA object:

  • The contents of an original and cloned PBDOM_CDATA object are exactly the same

  • A cloned PBDOM_CDATA initially has no parent object

  • A cloned PBDOM_CDATA is initially contained within the same owner document as the original

    PBDOM_BUILDER     pbdom_buildr
    PBDOM_DOCUMENT    pbdom_doc
    PBDOM_CDATA       pbdom_cdat
    PBDOM_OBJECT      pbdom_obj_array[]
    string strXML = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)>]><root><![CDATA[This is a CDATA Section.]]></root>"
    
    try
      // Build a PBDOM_DOCUMENT based on strXML.
      pbdom_buildr = Create PBDOM_BUILDER
      pbdom_doc = pbdom_buildr.BuildFromString (strXML)
    
      // Get the contents of the root element.
      pbdom_doc.GetRootElement().GetContent(pbdom_obj_array)
      
      // Test if the root element contains only one child object.
      if (UpperBound(pbdom_obj_array) = 1) then
        MessageBox ("Pass", "Root Element has only one child.")
      else
        MessageBox ("Fail", "Root Element must have only one child.")
      end if
    
      // Make a clone of the only child of the root element.
      pbdom_cdat = pbdom_obj_array[1].Clone(true)
    
      // Test if the clone is a PBDOM_CDATA object.
      if (pbdom_cdat.GetObjectClassString() = "pbdom_cdata") then
        MessageBox ("Pass", &
         "The first child, after being cloned, is indeed a PBDOM_CDATA object.")
      else
        MessageBox ("Fail", "The first child, after being cloned, " &
          + "is found to be a " + pbdom_cdat.GetObjectClassString() + " object.")
      end if
    
      // Test if the clone is a CDATA section.
      if (pbdom_cdat.GetText() = "This is a CDATA Section.") then
        MessageBox ("Pass", "The text contents of the clone is correct.")
      else
        MessageBox ("Fail", "The text contents of the clone is : [" &
          + pbdom_cdat.GetText() + "]. This is incorrect.")
      end if
      
      // Test that the clone has no parent.
      if (Not IsValid(pbdom_cdat.GetParentObject())) then
        MessageBox ("Pass", "The clone has no parent.")
      else
        MessageBox ("Fail", "The clone should have no parent.")
      end if
      
      // Test that the clone's owner document is the same 
      // as the original's owner document.
      if (pbdom_cdat.GetOwnerDocumentObject() = pbdom_doc) then
        MessageBox ("Pass", "The clone's owner document is correct.")
      else
        MessageBox ("Fail", "The clone's owner document is incorrect.")
      end if
      
    catch (PBDOM_EXCEPTION pbdom_except)
      MessageBox ("PBDOM_EXCEPTION", pbdom_except.GetMessage())
    end try

Usage

The Clone method creates a new PBDOM_CDATA object that is a duplicate of, and a separate object from, the original. The clone of a PBDOM_CDATA is always identical to its original whether deep or shallow cloning is invoked, because a PBDOM_CDATA object does not contain any subtree of child PBDOM_OBJECTs.

A PBDOM_CDATA clone has no parent. However, the clone resides in the same PBDOM_DOCUMENT as its original, and if the original PBDOM_CDATA is standalone, the clone is standalone.