Share via


XmlElement.RemoveAttribute Método

Definição

Remove o atributo especificado. (Se o atributo removido tiver um valor padrão, ele será substituído imediatamente).

Sobrecargas

RemoveAttribute(String)

Remove um atributo pelo nome.

RemoveAttribute(String, String)

Remove um atributo com o nome do local e o URI de namespace especificados. (Se o atributo removido tiver um valor padrão, ele será substituído imediatamente).

RemoveAttribute(String)

Remove um atributo pelo nome.

public:
 virtual void RemoveAttribute(System::String ^ name);
public virtual void RemoveAttribute (string name);
abstract member RemoveAttribute : string -> unit
override this.RemoveAttribute : string -> unit
Public Overridable Sub RemoveAttribute (name As String)

Parâmetros

name
String

O nome do atributo a ser removido. Este é um nome qualificado. Ele é comparado com a propriedade Name do nó correspondente.

Exceções

O nó é somente leitura.

Exemplos

O exemplo a seguir remove um atributo de um elemento.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   XmlElement^ root = doc->DocumentElement;
   
   // Remove the genre attribute.
   root->RemoveAttribute( "genre" );
   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->InnerXml );
}
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 the genre attribute.
    root.RemoveAttribute("genre");

    Console.WriteLine("Display the modified XML...");
    Console.WriteLine(doc.InnerXml);
  }
}
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 the genre attribute.
    root.RemoveAttribute("genre")

    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

Comentários

Se o atributo removido for conhecido por ter um valor padrão, um atributo será exibido imediatamente contendo o valor padrão e, se aplicável, o URI do namespace correspondente, o nome local e o prefixo.

Aplica-se a

RemoveAttribute(String, String)

Remove um atributo com o nome do local e o URI de namespace especificados. (Se o atributo removido tiver um valor padrão, ele será substituído imediatamente).

public:
 virtual void RemoveAttribute(System::String ^ localName, System::String ^ namespaceURI);
public virtual void RemoveAttribute (string localName, string namespaceURI);
public virtual void RemoveAttribute (string localName, string? namespaceURI);
abstract member RemoveAttribute : string * string -> unit
override this.RemoveAttribute : string * string -> unit
Public Overridable Sub RemoveAttribute (localName As String, namespaceURI As String)

Parâmetros

localName
String

O nome local do atributo a ser removido.

namespaceURI
String

O URI do namespace do atributo a ser removido.

Exceções

O nó é somente leitura.

Exemplos

O exemplo a seguir remove um atributo de um elemento.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 );
}
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);
  }
}
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

Comentários

Se o atributo removido for conhecido por ter um valor padrão, um atributo será exibido imediatamente contendo o valor padrão e, se aplicável, o URI do namespace correspondente, o nome local e o prefixo.

Aplica-se a