XmlElement.RemoveAttribute Metoda

Definicja

Usuwa określony atrybut. (Jeśli usunięty atrybut ma wartość domyślną, zostanie natychmiast zastąpiony).

Przeciążenia

RemoveAttribute(String)

Usuwa atrybut według nazwy.

RemoveAttribute(String, String)

Usuwa atrybut z określoną lokalną nazwą i identyfikatorem URI przestrzeni nazw. (Jeśli usunięty atrybut ma wartość domyślną, zostanie natychmiast zastąpiony).

RemoveAttribute(String)

Usuwa atrybut według nazwy.

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

Nazwa atrybutu do usunięcia. Jest to kwalifikowana nazwa. Jest on zgodny z właściwością Name pasującego węzła.

Wyjątki

Węzeł jest tylko do odczytu.

Przykłady

Poniższy przykład usuwa atrybut 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

Uwagi

Jeśli usunięty atrybut jest znany z wartości domyślnej, atrybut natychmiast pojawia się zawierający wartość domyślną i, jeśli ma to zastosowanie, odpowiedni identyfikator URI przestrzeni nazw, nazwa lokalna i prefiks.

Dotyczy

RemoveAttribute(String, String)

Usuwa atrybut z określoną lokalną nazwą i identyfikatorem URI przestrzeni nazw. (Jeśli usunięty atrybut ma wartość domyślną, zostanie natychmiast zastąpiony).

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

Nazwa lokalna atrybutu do usunięcia.

namespaceURI
String

Identyfikator URI przestrzeni nazw atrybutu do usunięcia.

Wyjątki

Węzeł jest tylko do odczytu.

Przykłady

Poniższy przykład usuwa atrybut 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

Uwagi

Jeśli usunięty atrybut jest znany z wartości domyślnej, atrybut natychmiast pojawia się zawierający wartość domyślną i, jeśli ma to zastosowanie, odpowiedni identyfikator URI przestrzeni nazw, nazwa lokalna i prefiks.

Dotyczy