SetAttribute Syntax 2
Description
Adds a PBDOM_ATTRIBUTE object and its value to a PBDOM_ELEMENT
object. Any existing attribute with the same name and namespace URI is
overwritten.
Syntax
|
1 |
pbdom_element_name.SetAttribute(string strName, string strValue) |
|
Argument |
Description |
|---|---|
|
pbdom_element_name |
The name of a PBDOM_ELEMENT object |
|
strName |
The name of the PBDOM_ATTRIBUTE to be |
|
strValue |
The value of the PBDOM_ATTRIBUTE to be |
Return value
PBDOM_ELEMENT. The PBDOM_ELEMENT object modified to contain the
specified PBDOM_ATTRIBUTE with the specified value.
Throws
EXCEPTION_INVALID_ARGUMENT — One or both of the input strings
are invalid. This can happen if either or both strings have not been
initialized properly or are null.
EXCEPTION_MEMORY_ALLOCATION_FAILURE — Insufficient memory was
encountered while executing this method.
EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE — This PBDOM_ELEMENT
object’s internal implementation is null. The occurrence of this
exception is rare but can take place if severe memory corruption
occurs.
EXCEPTION_INVALID_NAME — An invalid name for the attribute is
supplied.
EXCEPTION_INVALID_STRING — An invalid string for the attribute
value is supplied.
Examples
-
The SetAttribute method is invoked for the following XML
element:1<code0789725045</codeThe SetAttribute method is invoked from the following
PowerScript statement, where elem_code represents the code
element:1elem_code.SetAttribute("type", "ISBN")The following XML element results:
1<code type="ISBN">0789725045</code> -
The following example demonstrates the effect of setting an
attribute for a PBDOM_ELEMENT object when the PBDOM_ELEMENT object
already contains an attribute of the same name. The example
creates a PBDOM_DOCUMENT based on the following document:123<root xmlns:pre1="http://www.pre.com"><child1 pre1:a="123" b="456"/></root>The child1 element already contains an attribute named
b with value 456. Calling the SetAttribute method with name b and
value 789 creates a new attribute for child1 that replaces the
original b attribute.123456789101112PBDOM_BUILDER pbdom_buildrPBDOM_DOCUMENT pbdom_docstring strXML = "<root xmlns:pre1=~"http://www.pre.com~" ><child1 pre1:a=~"123~" b=~"456~"/></root>"trypbdom_buildr = Create PBDOM_BUILDERpbdom_doc = pbdom_buildr.BuildFromString (strXML)pbdom_doc.GetRootElement(). &GetChildElement("child1").SetAttribute("b", "789")catch (PBDOM_EXCEPTION except)MessageBox ("PBDOM_EXCEPTION", except.GetMessage())end tryAfter the PBDOM_DOCUMENT object is saved and converted to
XML, the XML document looks like the following:123<root xmlns:pre1="http://www.pre.com"><child1 pre1:a="123" b="789"/></root>
Usage
This method allows the caller to add an attribute/value pair to
a PBDOM_ELEMENT object. If the PBDOM_ELEMENT object already contains
an existing attribute that has the same name as the input name and
that belongs to no namespace, the original attribute is removed from
this PBDOM_ELEMENT object and a new one (corresponding to the
specified attribute name and value) is created and set in its
place.
If a PBDOM_ATTRIBUTE has been created to represent the original
attribute, it is still valid, but the attribute that it represents has
been detached from the original owner element. Calling
GetOwnerElementObject on this PBDOM_ATTRIBUTE returns a null
value.
See also