Description
Sets the input PBDOM_ELEMENT as the owner of the current PBDOM_ATTRIBUTE.
Syntax
pbdom_attribute_name.SetOwnerElementObject(pbdom_element pbdom_element_ref)
Argument |
Description |
---|---|
pbdom_attribute_name |
The name of the PBDOM_ATTRIBUTE |
pbdom_element_ref |
The PBDOM_ELEMENT to be set as the owner of this current PBDOM_ATTRIBUTE |
Return value
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:
PBDOM_BUILDER pbdombuilder_new PBDOM_DOCUMENT pbdom_doc PBDOM_ATTRIBUTE pbdom_attr PBDOM_ATTRIBUTE pbdom_attr_ns PBDOM_ELEMENT pbdom_elem_data string strXML = "<abc My_Attr=~"Attribute Value~" pre:My_Attr_NS=~"Attribute Value NS~" xmlns:pre=~"http://www.pre.com~"><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_ns = pbdom_doc.GetRootElement(). & GetAttribute("My_Attr_NS", "pre", & "http://www.pre.com") pbdom_elem_data = pbdom_doc.GetRootElement(). & GetChildElement("data") pbdom_attr.Detach() pbdom_attr.SetOwnerElementObject (pbdom_elem_data) pbdom_attr_ns.Detach() pbdom_attr_ns.SetOwnerElementObject (pbdom_elem_data) pbdom_doc.SaveDocument("setownerelementobject.xml") Destroy pbdombuilder_new Destroy pbdom_doc CATCH (PBDOM_Exception except) MessageBox ("Exception Occurred", except.Text) END TRY
When the document is serialized, the XML looks like this:
<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.
See also