Export (0) Print
Expand All

XmlElement.RemoveAttribute Method

Removes the specified attribute.

Note   If the removed attribute has a default value, it is immediately replaced.

Overload List

Removes an attribute by name.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Sub RemoveAttribute(String)
[C#] public virtual void RemoveAttribute(string);
[C++] public: virtual void RemoveAttribute(String*);
[JScript] public function RemoveAttribute(String);

Removes an attribute with the specified local name and namespace URI.

Note   If the removed attribute has a default value, it is immediately replaced.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Sub RemoveAttribute(String, String)
[C#] public virtual void RemoveAttribute(string, string);
[C++] public: virtual void RemoveAttribute(String*, String*);
[JScript] public function RemoveAttribute(String, String);

Example

[Visual Basic, C#, C++] The following example removes an attribute from an element.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of RemoveAttribute. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")

    Dim root as XmlElement = doc.DocumentElement

    ' Remove the ISBN attribute.
    root.RemoveAttribute("ISBN", "urn:samples")
    
    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Remove the ISBN attribute.
    root.RemoveAttribute("ISBN", "urn:samples");
     
    Console.WriteLine("Display the modified XML...");
    Console.WriteLine(doc.InnerXml);

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>");

    XmlElement* root = doc->DocumentElement;

    // Remove the ISBN attribute.
    root->RemoveAttribute(S"ISBN", S"urn:samples");
     
    Console::WriteLine(S"Display the modified XML...");
    Console::WriteLine(doc->InnerXml);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

XmlElement Class | XmlElement Members | System.Xml Namespace

Show:
© 2014 Microsoft