METHOD:  Element::setAttribute

Element.setAttribute(name, value)

The setAttribute method sets the value of the named attribute. If an attribute of the same name already exists in the element, then its value is changed to that of the 'value' parameter; if not, one is created. The value is a simple string and is not parsed when it is set. Therefore, any markup (such as syntax to be recognized as an entity reference) is treated as literal text and needs to be escaped by the implementation when it is written out.

To assign an attribute that contains entity references, the user must build an appropriate subtree of an Attr object and any Text and EntityReference objects, and assign it using the setAttributeNode method.

In the following example, we load the 'vocabulary.xml' file and call the setAttribute method to alter the 'level' attribute of the first 'Word' element to '2'. The code then displays the values of all the attributes.

   <Word type="noun" level="1">
   <Word type="verb" level="1">

Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False

Set Elem = objXMLDoc.documentElement.firstChild
Elem.setAttribute "level", "2"

Set NamedNodeMap = Elem.attributes
For Each Attr In NamedNodeMap
   document.write(Attr.value & "<br>")


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information