XmlElement.RemoveAttribute Metodo

Definizione

Rimuove l'attributo specificato. Se l'attributo rimosso ha un valore predefinito, viene immediatamente sostituito.

Overload

Nome Descrizione
RemoveAttribute(String)

Rimuove un attributo in base al nome.

RemoveAttribute(String, String)

Rimuove un attributo con il nome locale e l'URI dello spazio dei nomi specificati. Se l'attributo rimosso ha un valore predefinito, viene immediatamente sostituito.

RemoveAttribute(String)

Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs

Rimuove un attributo in base al 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)

Parametri

name
String

Nome dell'attributo da rimuovere. Si tratta di un nome completo. Viene confrontato con la Name proprietà del nodo corrispondente.

Eccezioni

Il nodo è di sola lettura.

Esempio

Nell'esempio seguente viene rimosso un attributo da un elemento .

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

Commenti

Se l'attributo rimosso è noto per avere un valore predefinito, viene immediatamente visualizzato un attributo contenente il valore predefinito e, se applicabile, l'URI dello spazio dei nomi, il nome locale e il prefisso corrispondenti.

Si applica a

RemoveAttribute(String, String)

Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs
Origine:
XmlElement.cs

Rimuove un attributo con il nome locale e l'URI dello spazio dei nomi specificati. Se l'attributo rimosso ha un valore predefinito, viene immediatamente sostituito.

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)

Parametri

localName
String

Nome locale dell'attributo da rimuovere.

namespaceURI
String

URI dello spazio dei nomi dell'attributo da rimuovere.

Eccezioni

Il nodo è di sola lettura.

Esempio

Nell'esempio seguente viene rimosso un attributo da un elemento .

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

Commenti

Se l'attributo rimosso è noto per avere un valore predefinito, viene immediatamente visualizzato un attributo contenente il valore predefinito e, se applicabile, l'URI dello spazio dei nomi, il nome locale e il prefisso corrispondenti.

Si applica a