Clone

Description

Creates and returns a clone of the current PBDOM_TEXT object.

Syntax

pbdom_text_name.Clone(boolean bDeep)

Argument

Description

pbdom_text_name

The name of a PBDOM_TEXT object.

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 parameter is ignored.


Return value

PBDOM_OBJECT. The return value is a clone of the current PBDOM_TEXT object returned as a PBDOM_OBJECT.

Examples

This example creates an XML document that, when serialized, appears as follows:

<!DOCTYPE root
[
<!ELEMENT root (child_1, child_2)>
<!ELEMENT child_1 (#PCDATA)*>
<!ELEMENT child_2 (#PCDATA)*>
]>
<root>
   <child_1>text for child.</child_1>
   <child_2>text for child.</child_2>
</root>

The definition of the DTD shows that the document is required to have the following composition:

  • The document contains a root element with the name root.

  • The root element contains a sequence of two child elements named child_1 and child_2.

  • Both child_1 and child_2 contain only text.

The following PowerScript code creates a PBDOM_TEXT object and assigns it a text value. It then creates a child_1 element, adds the PBDOM_TEXT object to it, creates a shallow clone of child_1, and names the clone child_2. After adding a clone of the text object to child_2, the code adds both child objects to the root element:

PBDOM_BUILDER     pbdom_buildr
PBDOM_DOCUMENT    pbdom_doc
PBDOM_ELEMENT     pbdom_elem_child_1
PBDOM_ELEMENT     pbdom_elem_child_2
PBDOM_TEXT        pbdom_txt
string strXML = "<!DOCTYPE root [<!ELEMENT root (child_1, child_2)><!ELEMENT child_1 (#PCDATA)><!ELEMENT child_2 (#PCDATA)>]><root/>"

try
  pbdom_buildr = Create PBDOM_BUILDER 
  pbdom_doc = pbdom_buildr.BuildFromString (strXML)

  pbdom_txt = Create PBDOM_TEXT
  pbdom_txt.SetText ("text for child.")
  
  pbdom_elem_child_1 = Create PBDOM_ELEMENT
  pbdom_elem_child_1.SetName ("child_1")
  pbdom_elem_child_1.AddContent (pbdom_txt)
  
  pbdom_elem_child_2 = pbdom_elem_child_1.Clone(false)
  pbdom_elem_child_2.SetName("child_2")
  pbdom_elem_child_2.AddContent (pbdom_txt.Clone(false))
  
  pbdom_doc.GetRootElement().AddContent(pbdom_elem_child_1)
  pbdom_doc.GetRootElement().AddContent(pbdom_elem_child_2)
  
  pbdom_doc.SaveDocument ("sample.xml")
  
catch (PBDOM_EXCEPTION pbdom_except)
  MessageBox ("PBDOM_EXCEPTION", pbdom_except.GetMessage())
end try

Usage

The Clone method creates a new PBDOM_TEXT object that is a duplicate of, and a separate object from, the original. Whether true or false is supplied as the parameter to this function, a PBDOM_TEXT clone is always identical to its original. This is because a PBDOM_TEXT does not contain any subtree of children PBDOM_OBJECTs.

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