PBDOM_ATTRIBUTE:
SetOwnerElementObject method
Description
Sets
the input PBDOM_ELEMENT as the owner of the current PBDOM_ATTRIBUTE.
Syntax
|
1 |
<span>pbdom_attribute_name</span>.SetOwnerElementObject(pbdom_element <span>pbdom_element_ref</span>) |
|
Argument |
Description |
|---|---|
|
pbdom_attribute_name |
The name of the PBDOM_ATTRIBUTE |
|
pbdom_element_ref |
The PBDOM_ELEMENT to be set |
Return Values
PBDOM_ATTRIBUTE. This PBDOM_ATTRIBUTE itself
modified and returned.
Throws
EXCEPTION_INVALID_ARGUMENT – The
input PBDOM_ELEMENT is invalid. This can happen if it has
not been initialized properly or is a null object reference.
EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE – The
internal implementation of the PBDOM_ATTRIBUTE object or
the input PBDOM_ELEMENT object is null.
The occurrence of this exception is rare but can take place if severe
memory corruption occurs.
EXCEPTION_PBDOM_OBJECT_ALREADY_HAS_OWNER – This PBDOM_ATTRIBUTE
already has an owner Element.
EXCEPTION_USE_OF_UNNAMED_PBDOM_OBJECT – The
input PBDOM_ELEMENT has not been named.
EXCEPTION_INVALID_NAME – The
input PBDOM_ELEMENT already contains an attribute that
has the same name and that belongs to the same namespace as this
current PBDOM_ATTRIBUTE.
Examples
This example moves the positions of two PBDOM_ATTRIBUTE
objects from one element to another.
In the string strXML from which a PBDOM_DOCUMENT
is created, the abc root element contains a
namespace declaration and two attributes. My_Attr belongs
to no namespace, and pre:My_Attr_NS belongs
to the http://www.pre.com namespace. The example
obtains handles for the two attributes and the data element,
then detaches both attributes from abc and
sets data as their new owner:
|
1 |
PBDOM_BUILDER     pbdombuilder_new<br>PBDOM_DOCUMENT    pbdom_doc<br>PBDOM_ATTRIBUTE   pbdom_attr<br>PBDOM_ATTRIBUTE   pbdom_attr_ns<br>PBDOM_ELEMENT     pbdom_elem_data<br>string strXML = "<abc My_Attr=~"Attribute Value~" pre:My_Attr_NS=~"Attribute Value NS~" xmlns:pre=~"http://www.pre.com~"><data>Data</data></abc>"<br> <br>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_ns = pbdom_doc.GetRootElement(). &<br>    GetAttribute("My_Attr_NS", "pre", &<br>    "http://www.pre.com")<br> pbdom_elem_data = pbdom_doc.GetRootElement(). &<br>    GetChildElement("data")<br> <br> pbdom_attr.Detach()<br> pbdom_attr.SetOwnerElementObject (pbdom_elem_data)<br> <br> pbdom_attr_ns.Detach()<br> pbdom_attr_ns.SetOwnerElementObject (pbdom_elem_data)<br> <br> pbdom_doc.SaveDocument("setownerelementobject.xml")<br> <br> Destroy pbdombuilder_new<br> Destroy pbdom_doc<br> <br>CATCH (PBDOM_Exception except)<br> MessageBox ("Exception Occurred", except.Text)<br>END TRY |
When the document is serialized, the XML looks like this:
|
1 |
<abc xmlns:pre="http://www.pre.com"><data pre:My_Attr_NS="Attribute Value NS" My_Attr="Attribute Value">Data</data></abc> |
Usage
According to the “Namespace in XML” specifications,
an element cannot contain two attributes with the same local name
and namespace URI. This is true even if the prefixes of the two
attributes are different. An exception is thrown if this rule is
violated when SetOwnerElementObject is invoked.