Export (0) Print
Expand All

XmlElement.RemoveAllAttributes Method

Removes all specified attributes from the element. Default attributes are not removed.

[Visual Basic]
Public Overridable Sub RemoveAllAttributes()
[C#]
public virtual void RemoveAllAttributes();
[C++]
public: virtual void RemoveAllAttributes();
[JScript]
public function RemoveAllAttributes();

Remarks

This method is a Microsoft extension to the Document Object Model (DOM).

Example

[Visual Basic, C#, C++] The following example removes all attributes from the root element.

[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 genre='novel' ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")      

    Dim root as XmlElement = doc.DocumentElement

    ' Remove all attributes from the root element.
    root.RemoveAllAttributes()

    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 genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Remove all attributes from the root element.
    root.RemoveAllAttributes();
    
    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 genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>");

    XmlElement* root = doc->DocumentElement;

    // Remove all attributes from the root element.
    root->RemoveAllAttributes();
    
    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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlElement Class | XmlElement Members | System.Xml Namespace

Show:
© 2014 Microsoft