setAttributeNode Method
Sets or updates the supplied attribute node on this element.
var objXMLDOMAttribute = oXMLDOMElement.XMLDOMElement(DOMAttribute);
Parameters
Return Value
An object. Returns Null unless the new attribute replaces an existing attribute with the same name, in which case this method returns the previous, replaced attribute node.
Example
Note |
|---|
You can use books.xml to run this sample code. |
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); var nodeBook, nodePublishDate; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; WScript.Echo("You have error " + myErr.reason); } else { nodePublishDate = xmlDoc.createAttribute("PublishDate"); nodePublishDate.value = String(Date()); nodeBook = xmlDoc.selectSingleNode("//book"); nodeBook.setAttributeNode(nodePublishDate); WScript.Echo(nodeBook.getAttribute("PublishDate")); }
Output
Outputs the current date and time in the following format:
Thu Jun 12 14:12:38 2003
(Thursday, June 12, 2003, 2:12:38 pm)
Note