METHOD:  Document::createAttribute


The createAttribute method creates an Attr object of the specified name. It does not, however, add a value for that attribute. This must be done separately using the Element object's setAttribute method. An attribute so created will have a parentNode property set to null until it has been 'set' into an element.

To demonstrate this, the following example creates two attributes ('ID' and 'catalog') and sets them in the first 'book' element. A NamedNodeMap is created from this element and then the code loops through each attribute and displays the associated XML.

      <title>Eyeless in Gaza</title>
      <author>Aldous Huxley</author>
      <title>John Barleycorn</title>
      <author>Jack London</author>

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

Dim objNamedNodeMap, objCurrNode, objIdAttr, objCatAttr, index
Set objIdAttr = objXMLDoc.createAttribute("ID")
Set objCatAttr = objXMLDoc.createAttribute("catalog")
Set objCurrNode = objXMLDoc.documentElement.firstChild
objCurrNode.setAttribute "ID", "0173"
objCurrNode.setAttribute "catalog", "DL-3678"

Set objNamedNodeMap = objCurrNode.attributes
For index = 0 To objNamedNodeMap.length-1
   document.write(objNamedNodeMap.item(index).xml & "<br>")


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