setAttributeNode (DOMElement - JavaScript)

Assigns an attribute to an element.

Defined in

DOMElement

Syntax

setAttributeNode(attribute:DOMAttr) : DOMAttr

Parameters Description
attribute The attribute.
Return value Description
DOMAttr The attribute.

Usage

The specified attribute is assigned to this element.

Examples

This button creates a document with a hierarchy of elements and sets an attribute for the end node.
var doc = database.createNewDocument();
var dom = doc.getDOM();
var schema0 = dom.createElement("schema0");
var element0 = dom.createElement("element0");
var attr = dom.createAttribute("Owner");
attr.setValue(session.getCommonUserName());
dom.appendChild(schema0);
schema0.appendChild(element0);
element0.setStringValue(requestScope.s);
element0.setAttributeNode(attr);
doc.save()
The XML for this document might appear as follows:
<schema0>
  <element0 Owner="wpsadmin">foo</element0>
</schema0>