Sets or updates the supplied attribute node on this element.
var objXMLDOMAttribute = oXMLDOMElement.XMLDOMElement(DOMAttribute);
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.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var nodeBook, nodePublishDate;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode <> 0) {
var myErr = xmlDoc.parseError;
alert("You have error " + myErr.reason);
} else {
nodePublishDate = xmlDoc.createAttribute("PublishDate");
nodePublishDate.value = String(Date());
nodeBook = xmlDoc.selectSingleNode("//book");
nodeBook.setAttributeNode(nodePublishDate);
alert(nodeBook.getAttribute("PublishDate"));
}
Set objXMLDOMAttribute = oXMLDOMElement.XMLDOMElement(DOMAttribute)
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.
Dim xmlDoc As New Msxml2.DOMDocument50
Dim nodeBook As IXMLDOMElement
Dim nodePublishDate As IXMLDOMAttribute
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 nodePublishDate = xmlDoc.createAttribute("PublishDate")
nodePublishDate.Value = Now
Set nodeBook = xmlDoc.selectSingleNode("//book")
nodeBook.setAttributeNode nodePublishDate
MsgBox nodeBook.getAttribute("PublishDate")
End If
HRESULT setAttributeNode(
IXMLDOMAttribute *DOMAttribute,
IXMLDOMAttribute **attributeNode);
See the example in the getAttributeNode method.
You cannot add an existing attribute to an element until you first remove it from its previous element. Also, you cannot add a namespace-qualified attribute when it uses the same prefix as another attribute with a different namespaceURI.
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.
Applies to: IXMLDOMElement