Removes the specified attribute from this element.
var objXMLDOMAttribute = oXMLDOMElement.removeAttributeNode(DOMAttribute);
IXMLDOMAttribute object to be removed from this element.An object. Returns the removed element.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var nodeBook, nodeId;
xmlDoc.setProperty("SelectionLanguage", "XPath");
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");
nodeId = nodeBook.getAttributeNode("id");
alert(nodeBook.attributes.length);
nodeBook.removeAttributeNode(nodeId);
alert(nodeBook.attributes.length);
}
Set objXMLDOMAttribute = oXMLDOMElement.removeAttributeNode(DOMAttribute)
IXMLDOMAttribute object to be removed from this element.An object. Returns the removed element.
Dim xmlDoc As New Msxml2.DOMDocument50
Dim nodeBook As IXMLDOMElement
Dim nodeId As IXMLDOMAttribute
xmlDoc.setProperty "SelectionLanguage", "XPath"
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")
Set nodeId = nodeBook.getAttributeNode("id")
MsgBox nodeBook.Attributes.length
nodeBook.removeAttributeNode nodeId
MsgBox nodeBook.Attributes.length
End If
HRESULT removeAttributeNode(
IXMLDOMAttribute *DOMAttribute,
IXMLDOMAttribute **attributeNode);
DOMAttribute object that is to be removed from this element.IXMLDOMElement *pIXMLDOMElement = NULL;
_bstr_t bstrAttributeName = _T("dateCreated");
IXMLDOMAttribute *pIXMLDOMAttribute = NULL;
IXMLDOMAttribute *pRemovedIXMLDOMAttribute = NULL;
IXMLDOMDocument *pIXMLDOMDocument = NULL;
HRESULT hr;
try
{
// Create an instance of DOMDocument and initialize pIXMLDOMDocument.
// Load/create an XML fragment.
hr = pIXMLDOMDocument->get_documentElement(&pIXMLDOMElement);
SUCCEEDED(hr) ? 0 : throw hr;
if(pIXMLDOMElement)
{
hr = pIXMLDOMElement->getAttributeNode(bstrAttributeName, &pIXMLDOMAttribute);
if(SUCCEEDED(hr) && pIXMLDOMAttribute)
{
hr = pIXMLDOMElement->removeAttributeNode(pIXMLDOMAttribute, &pRemovedIXMLDOMAttribute);
if(SUCCEEDED(hr))
// Attribute node removed.
bResult = TRUE;
pIXMLDOMAttribute->Release();
}
pIXMLDOMElement->Release();
}
// Release pIXMLDOMDocument when finished with it.
}
catch(...)
{
// Release pIXMLDOMDocument if it exists.
if(pIXMLDOMAttribute)
pIXMLDOMAttribute->Release();
if(pIXMLDOMElement)
pIXMLDOMElement->Release();
DisplayErrorToUser();
}
If the attribute has a default value, this call also creates a new attribute with the default value, associates the new attribute with this element, and resets the attribute's specified property.
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.
specified Property | IXMLDOMAttribute
Applies to: IXMLDOMElement