removeAttributeNode Method
Removes the specified attribute from this element.
[Script]
Script Syntax
var objXMLDOMAttribute = oXMLDOMElement.removeAttributeNode(DOMAttribute);
Parameters
- DOMAttribute
- An object that supplies the
IXMLDOMAttribute
object to be removed from this element.
Return Value
An object. Returns the removed element.
Example
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); }
[Visual Basic]
Visual Basic Syntax
Set objXMLDOMAttribute = oXMLDOMElement.removeAttributeNode(DOMAttribute)
Parameters
- DOMAttribute
- An object that supplies the
IXMLDOMAttribute
object to be removed from this element.
Return Value
An object. Returns the removed element.
Example
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
[C/C++]
C/C++ Syntax
HRESULT removeAttributeNode( IXMLDOMAttribute *DOMAttribute, IXMLDOMAttribute **attributeNode);
Parameters
- DOMAttribute [in]
- The
DOMAttribute
object that is to be removed from this element. - attributeNode [out, retval]
- The removed element.
C/C++ Return Values
- S_OK
- The value returned if successful.
- E_FAIL
- The value returned if an error occurs.
C/C++ Example
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(); }
Remarks
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.
See Also
specified Property | IXMLDOMAttribute
Applies to: IXMLDOMElement