XmlElement.RemoveAttribute Metoda

Definice

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

Přetížení

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, je okamžitě nahrazen).

RemoveAttribute(String)

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. Jedná se o kvalifikovaný název. Odpovídá Name vlastnosti 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.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

Poznámky

Pokud je odebraný atribut známý jako výchozí hodnota, zobrazí se atribut okamžitě 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)

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

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.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

Poznámky

Pokud je odebraný atribut známý jako výchozí hodnota, zobrazí se atribut okamžitě 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