XmlElement.RemoveAttribute Metoda

Definice

Odebere zadaný atribut. (Pokud odebraný atribut má výchozí hodnotu, okamžitě se nahradí).

Přetížení

Name Description
RemoveAttribute(String)

Odebere atribut podle názvu.

RemoveAttribute(String, String)

Odebere atribut se zadaným místním názvem a identifikátorem URI oboru názvů. (Pokud odebraný atribut má výchozí hodnotu, okamžitě se nahradí).

RemoveAttribute(String)

Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs

Odebere atribut podle názvu.

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)

Parametry

name
String

Název atributu, který chcete odebrat. Toto je kvalifikovaný název. Porovná se Name s vlastností odpovídajícího uzlu.

Výjimky

Uzel je jen pro čtení.

Příklady

Následující příklad odebere atribut z elementu.

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

Poznámky

Pokud je odebraný atribut znám jako výchozí hodnota, atribut se okamžitě zobrazí obsahující výchozí hodnotu a v případě potřeby odpovídající identifikátor URI oboru názvů, místní název a předponu.

Platí pro

RemoveAttribute(String, String)

Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs
Zdroj:
XmlElement.cs

Odebere atribut se zadaným místním názvem a identifikátorem URI oboru názvů. (Pokud odebraný atribut má výchozí hodnotu, okamžitě se nahradí).

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)

Parametry

localName
String

Místní název atributu, který chcete odebrat.

namespaceURI
String

Identifikátor URI oboru názvů atributu, který chcete odebrat.

Výjimky

Uzel je jen pro čtení.

Příklady

Následující příklad odebere atribut z elementu.

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

Poznámky

Pokud je odebraný atribut znám jako výchozí hodnota, atribut se okamžitě zobrazí obsahující výchozí hodnotu a v případě potřeby odpovídající identifikátor URI oboru názvů, místní název a předponu.

Platí pro