PBDOM_ATTRIBUTE:
Detach method
Description
Detaches
a PBDOM_ATTRIBUTE from its owner PBDOM_OBJECT,
a PBDOM_ELEMENT.
Syntax
1 |
<span>pbdom_attribute_name.</span>Detach() |
Argument |
Description |
---|---|
pbdom_attribute_name |
The name of the PBDOM_ATTRIBUTE |
Return Values
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:
1 |
PBDOM_BUILDER          pbdombuilder_new<br>PBDOM_DOCUMENT         pbdom_doc<br>PBDOM_ATTRIBUTE        pbdom_attr<br>PBDOM_ELEMENT          pbdom_elem<br>string strXML = "<abc My_Attr=~"My Attribute Value~"><data>Data</data></abc>"<br> |
1 |
TRY<br>  pbdombuilder_new = Create PBDOM_Builder<br>  pbdom_doc = pbdombuilder_new.BuildFromString (strXML)<br> <br>  pbdom_attr = pbdom_doc.GetRootElement(). &<br>     GetAttribute("My_Attr")<br>  pbdom_attr.Detach()<br> <br>  pbdom_elem = pbdom_doc.GetRootElement(). &<br>     GetChildElement("data")<br>  pbdom_elem.SetAttribute (pbdom_attr)<br> <br>  Destroy pbdombuilder_new<br>  Destroy pbdom_doc<br> <br>CATCH (PBDOM_Exception except)<br>   MessageBox ("Exception Occurred", except.Text)<br>END TRY |
Here, the PBDOM_Builder BuildFromString method
is used to create the following PBDOM_DOCUMENT object, pbdom_doc,
using an XML string:
1 |
<abc My_Attr="My Attribute Value"><br>   <data>Data </data><br></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:
1 |
<abc><br>   <data My_Attr="My Attribute Value">Data</data><br></abc> |
Usage
If the PBDOM_ATTRIBUTE object has no owner PBDOM_ELEMENT,
the Detach method does nothing.