createAttribute (DOMDocument - JavaScript)

Creates an attribute.

Defined in

DOMDocument

Syntax

createAttribute(name:string) : DOMAttr

Parameters Description
name A legal name for the attribute.
Return value Description
DOMAttr The attribute.

Usage

This method does not set a value for the attribute nor assign it to an element. You must, for example, set the attribute value with setValue in DOMAttr and assign it to an element with setAttributeNode in DOMElement.

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>