GetOwnerDocumentObject

Description

The GetOwnerDocumentObject method returns the owning PBDOM_DOCUMENT of the current PBDOM_CHARACTERDATA.

Syntax

pbdom_chardata_name.GetOwnerDocumentObject()

Argument

Description

pbdom_chardata_name

The name of a PBDOM_CHARACTERDATA object


Return value

PBDOM_OBJECT.

Throws

EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- If this PBDOM_CHARACTERDATA is not associated with a derived PBDOM_CHARACTERDATA class.

Examples

  1. This example creates a PBDOM_DOCUMENT based on the following DOM tree:

    <abc>
       <data>Data</data>
    </abc>

    The PowerScript code obtains the root element, uses it to obtain the child element, and then obtains an array of the child element's own children. This array has a single item, the PBDOM_TEXT object with the text Data. The array can be cast to a PBDOM_CHARACTERDATA object because it does not contain any objects that are not derived from PBDOM_CHARACTERDATA,

    The call to GetOwnerDocumentObject returns a PBDOM_OBJECT, which is stored in a PBDOM_DOCUMENT called pbdom_owner_doc. The call to Equals tests whether the owner document of the "Data" PBDOM_TEXT and the main document, referenced using pbdom_doc, refer to the same document.

    PBDOM_Builder         pbdombuilder_new
    pbdom_document        pbdom_doc
    pbdom_document        pbdom_owner_doc
    pbdom_element         pbdom_elem
    PBDOM_CHARACTERDATA   pbdom_chardata
    PBDOM_OBJECT          pbdom_obj_array[]
    string strXML = "<abc><data>Data</data></abc>"
    
    TRY
       pbdombuilder_new = Create PBDOM_Builder
       pbdom_doc = pbdombuilder_new.BuildFromString (strXML)
    
       pbdom_elem = pbdom_doc.GetRootElement(). &
          GetChildElement("data")
       pbdom_elem.GetContent(pbdom_obj_array)
    
       pbdom_chardata = pbdom_obj_array[1]
    
       pbdom_owner_doc = &
          pbdom_chardata.GetOwnerDocumentObject()
    
       if (pbdom_doc.Equals(pbdom_owner_doc)) then
          MessageBox ("Equals", &
             "pbdom_doc Equals pbdom_owner_doc")
       else
          MessageBox ("Equals", &
             "pbdom_doc Not Equals pbdom_owner_doc")
       end if
    
       Destroy pbdombuilder_new
    
    CATCH (PBDOM_Exception except)
       MessageBox ("Exception Occurred", except.Text)
    END TRY
  2. This example creates a PBDOM_DOCUMENT based on the same DOM tree as example 1. It creates a PBDOM_TEXT, stores it in the PBDOM_CHARACTERDATA variable pbdom_chardata, and assigns it some text. Objects created in this way are standalone objects -- they have no owner document or parent. Calling GetOwnerDocumentObject on pbdom_chardata returns null.

    The code then adds pbdom_chardata as a child to the data element. This implicitly imports pbdom_chardata into the original document. pbdom_chardata now has an owner document and a parent (the data element). Calling GetOwnerDocumentObject on pbdom_chardata returns the original document. When the returned PBDOM_DOCUMENT has been assigned into pbdom_owner_doc, a call to Equals to compare pbdom_doc with pbdom_owner_doc returns true:

    PBDOM_Builder          pbdombuilder_new
    pbdom_document         pbdom_doc
    pbdom_document         pbdom_owner_doc
    PBDOM_CHARACTERDATA    pbdom_chardata
    string strXML = "<abc><data>Data</data></abc>"
    
    TRY
       pbdombuilder_new = Create PBDOM_Builder
       pbdom_doc = pbdombuilder_new.BuildFromString (strXML)
    
       pbdom_chardata = Create PBDOM_TEXT
       pbdom_chardata.SetText(" Some Text")
    
       if (IsValid (pbdom_chardata.GetOwnerDocumentObject())) then
          MessageBox ("Owner Document", &
             "PBDOM_TEXT (~'Some Text~') has an owner document.")
       else
         MessageBox ("Owner Document", &
             "PBDOM_TEXT (~'Some Text~') has NO owner document.")   
       end if
    
       pbdom_doc.GetRootElement().GetChildElement("data"). &
          AddContent(pbdom_chardata)
    
       pbdom_owner_doc = pbdom_chardata.GetOwnerDocumentObject()
    
       if (pbdom_doc.Equals(pbdom_owner_doc)) then
          MessageBox ("Equals", "pbdom_doc Equals pbdom_owner_doc")
       else
         MessageBox ("Equals", "pbdom_doc Not Equals pbdom_owner_doc")
       end if
    
       Destroy pbdombuilder_new
       Destroy pbdom_chardata
    
    CATCH (PBDOM_Exception except)
       MessageBox ("Exception Occurred", except.Text)
    END TRY

Usage

If there is no owning PBDOM_DOCUMENT, null is returned.

See also

GetParentObject

SetParentObject