Sets the value of the named attribute.
oXMLDOMElement.setAttribute(name, value);
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var nodeBook; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { nodeBook = xmlDoc.selectSingleNode("//book"); nodeBook.setAttribute("PublishDate", String(Date())) alert(nodeBook.getAttribute("PublishDate")); }
oXMLDOMElement.setAttribute(name, value)
Dim xmlDoc As New Msxml2.DOMDocument50 Dim nodeBook As IXMLDOMElement xmlDoc.async = False xmlDoc.Load "books.xml" If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set nodeBook = xmlDoc.selectSingleNode("//book") nodeBook.setAttribute "PublishDate", Now MsgBox nodeBook.getAttribute("PublishDate") End If
HRESULT setAttribute( BSTR name, VARIANT value);
See the example in the getAttribute
method.
If an attribute with the supplied name already exists, this method changes its value to the supplied value
parameter. The supplied string is not parsed, so any markup, such as syntax intended to be recognized as an entity reference, is treated as literal text and must be appropriately escaped by the implementation when it is written out.
To assign an attribute value that contains entity references, the user must create IXMLDOMAttribute
plus any IXMLDOMText
and IXMLDOMEntityReference
objects, build the appropriate subtree, and call the setAttributeNode
method.
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
IXMLDOMAttribute | IXMLDOMText | IXMLDOMEntityReference | setAttributeNode method
Applies to: IXMLDOMElement