Export (0) Print
Expand All
DOM
Expand Minimize

removeAttributeNode Method

Removes the specified attribute from this element.

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

NoteNote

You can use books.xml to run this sample code.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
var nodeBook, nodeId;
xmlDoc.setProperty("SelectionLanguage", "XPath");
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   nodeBook = xmlDoc.selectSingleNode("//book");
   nodeId = nodeBook.getAttributeNode("id");
   WScript.Echo(nodeBook.attributes.length);
   nodeBook.removeAttributeNode(nodeId);
   WScript.Echo(nodeBook.attributes.length);
}


Output

1

0

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.

Return Values

S_OK

The value returned if successful.

E_FAIL

The value returned if an error occurs.

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();
      }


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.

Implemented in: MSXML 3.0 and lMSXML 6.0

Show:
© 2014 Microsoft