Detach

Description

Detaches a PBDOM_ATTRIBUTE from its owner PBDOM_OBJECT, a PBDOM_ELEMENT.

Syntax

pbdom_attribute_name.Detach()

Argument

Description

pbdom_attribute_name

The name of the PBDOM_ATTRIBUTE


Return value

PBDOM_OBJECT. The PBDOM_ATTRIBUTE object detached from its owner object.

Throws

EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- This PBDOM_ATTRIBUTE object's internal implementation is null. The occurrence of this exception is rare but can take place if severe memory corruption occurs.

Examples

The Detach method can be used to manipulate an XML document as follows:

PBDOM_BUILDER          pbdombuilder_new
PBDOM_DOCUMENT         pbdom_doc
PBDOM_ATTRIBUTE        pbdom_attr
PBDOM_ELEMENT          pbdom_elem
string strXML = "<abc  My_Attr=~"My Attribute Value~"><data>Data</data></abc>"


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

  pbdom_attr = pbdom_doc.GetRootElement(). &
     GetAttribute("My_Attr")
  pbdom_attr.Detach()

  pbdom_elem = pbdom_doc.GetRootElement(). &
     GetChildElement("data")
  pbdom_elem.SetAttribute (pbdom_attr)

  Destroy pbdombuilder_new
  Destroy pbdom_doc

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

Here, the PBDOM_Builder BuildFromString method is used to create the following PBDOM_DOCUMENT object, pbdom_doc, using an XML string:

<abc  My_Attr="My Attribute Value">
   <data>Data </data>
</abc>

The GetAttribute method is used to obtain the attribute from the root element of pbdom_doc. This value is assigned to the PBDOM_ATTRIBUTE object pbdom_attr. The pbdom_attr object is detached from its parent element, and the data element is obtained from pbdom_doc using the GetChildElement method. The data element is then assigned to the PBDOM_ELEMENT object pbdom_elem. The attribute assigned to pbdom_attr is assigned to pbdom_elem, yielding the following modified pbdom_doc:

<abc>
   <data My_Attr="My Attribute Value">Data</data>
</abc>

Usage

If the PBDOM_ATTRIBUTE object has no owner PBDOM_ELEMENT, the Detach method does nothing.