SetParentObject

Description

The SetParentObject method sets the referenced PBDOM_OBJECT to be the parent of the current PBDOM_CHARACTERDATA.

Syntax

pbdom_chardata_name.SetParentObject(pbdom_object pbdom_object_ref)

Argument

Description

pbdom_chardata_name

The name of a PBDOM_CHARACTERDATA

pbdom_object_ref

A PBDOM_OBJECT to be set as the parent of this PBDOM_CHARACTERDATA object


Return value

PBDOM_OBJECT.

Throws

EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- If this PBDOM_CHARACTERDATA is not a reference to an object derived from PBDOM_CHARACTERDATA. This exception also occurs if the input PBDOM_OBJECT is not a reference to an object derived from PBDOM_OBJECT.

EXCEPTION_PBDOM_OBJECT_ALREADY_HAS_PARENT -- If the current PBDOM_CHARACTERDATA already has a parent.

EXCEPTION_INAPPROPRIATE_USE_OF_PBDOM_OBJECT -- If the input PBDOM_OBJECT is of a class that does not have a proper parent-child relationship with the class of this PBDOM_CHARACTERDATA.

EXCEPTION_USE_OF_UNNAMED_PBDOM_OBJECT -- If the input PBDOM_OBJECT requires a user-defined name, and it has not been named.

Examples

This example creates a PDBOM_DOCUMENT based on the following DOM tree:

<abc>
   <data>
      <child_1/>
      <child_2/>
      <child_3/>
</data>
</abc>

The code creates three separate types of PBDOM_CHARACTERDATA objects and stores them in the pbdom_chardata array. It then obtains the root element, uses it to obtain the data child element, and then uses that to obtain the first child element, which it sets as the parent of the first item in the pbdom_chardata array.

The text of the array item is set to Comment. You can set the string content of any PBDOM_CHARACTERDATA object after you have set it as the child of a parent.

The same process is repeated for the text and CDATA objects:

PBDOM_Builder        pbdombuilder_new
pbdom_document       pbdom_doc
PBDOM_CHARACTERDATA  pbdom_chardata[]
PBDOM_ELEMENT        pbdom_elem
long                 = 0
string strXML = "<abc><data><child_1/><child_2/><child_3/></data></abc>"

TRY
 pbdombuilder_new = Create PBDOM_Builder
 pbdom_doc = pbdombuilder_new.BuildFromString (strXML)

 pbdom_chardata[1] = Create PBDOM_COMMENT
 pbdom_chardata[2] = Create PBDOM_TEXT
 pbdom_chardata[3] = Create PBDOM_CDATA

 pbdom_elem = pbdom_doc.GetRootElement(). &
    GetChildElement("data").GetChildElement("child_1")
 pbdom_chardata[1].SetParentObject (pbdom_elem)
 pbdom_chardata[1].SetText ("Comment")

 pbdom_elem = pbdom_doc.GetRootElement(). &
    GetChildElement("data").GetChildElement("child_2")
 pbdom_chardata[2].SetParentObject (pbdom_elem)
 pbdom_chardata[2].SetText ("Text")

 pbdom_elem = pbdom_doc.GetRootElement(). &
    GetChildElement("data").GetChildElement("child_3")
 pbdom_chardata[3].SetParentObject (pbdom_elem)
 pbdom_chardata[3].SetText ("CDATA")

 pbdom_doc.SaveDocument ("c:\pbdom_doc_1.xml")

 Destroy pbdombuilder_new

CATCH (PBDOM_Exception except)
 MessageBox ("Exception Occurred", except.Text)
END TRY

When the PBDOM_DOCUMENT is saved to a file, the output DOM tree looks like this:

<abc>
   <data>
      <child_1>
         <!--Comment-->
      </child_1>
      <child_2>
         Text
      </child_2>
      <child_3>
         <![CDATA[CDATA]]>
      </child_3>
   </data>
</abc>

Usage

The PBDOM_OBJECT that you set to be the parent of the current PBDOM_CHARACTERDATA must have a legal parent-child relationship. If it does not, an exception is thrown.

See also

GetParentObject