XmlElement.RemoveAttribute XmlElement.RemoveAttribute XmlElement.RemoveAttribute XmlElement.RemoveAttribute Method

定義

移除指定的屬性Removes the specified attribute. (如果移除的屬性具有預設值,會立即被取代)。(If the removed attribute has a default value, it is immediately replaced).

多載

RemoveAttribute(String) RemoveAttribute(String) RemoveAttribute(String) RemoveAttribute(String)

依照名稱移除屬性。Removes an attribute by name.

RemoveAttribute(String, String) RemoveAttribute(String, String) RemoveAttribute(String, String) RemoveAttribute(String, String)

移除具有指定區域名稱和命名空間 URI 的屬性Removes an attribute with the specified local name and namespace URI. (如果移除的屬性具有預設值,會立即被取代)。(If the removed attribute has a default value, it is immediately replaced).

RemoveAttribute(String) RemoveAttribute(String) RemoveAttribute(String) RemoveAttribute(String)

依照名稱移除屬性。Removes an attribute by name.

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)

參數

name
String String String String

所要移除屬性 (Attribute) 的名稱。這是一個限定名稱。The name of the attribute to remove.This is a qualified name. 它會與符合節點的 Name 屬性比對。It is matched against the Name property of the matching node.

例外狀況

節點為唯讀。The node is read-only.

範例

下列範例會從元素移除屬性。The following example removes an attribute from an element.

#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

備註

如果已移除的屬性已知有預設值, 則會立即出現屬性, 其中包含預設值, 以及對應的命名空間 URI、區功能變數名稱稱和前置詞 (如果適用的話)。If the removed attribute is known to have a default value, an attribute immediately appears containing the default value and, if applicable, the corresponding namespace URI, local name, and prefix.

RemoveAttribute(String, String) RemoveAttribute(String, String) RemoveAttribute(String, String) RemoveAttribute(String, String)

移除具有指定區域名稱和命名空間 URI 的屬性Removes an attribute with the specified local name and namespace URI. (如果移除的屬性具有預設值,會立即被取代)。(If the removed attribute has a default value, it is immediately replaced).

public:
 virtual void RemoveAttribute(System::String ^ localName, System::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)

參數

localName
String String String String

要移除的屬性的區域名稱。The local name of the attribute to remove.

namespaceURI
String String String String

要移除的屬性的命名空間 URI。The namespace URI of the attribute to remove.

例外狀況

節點為唯讀。The node is read-only.

範例

下列範例會從元素移除屬性。The following example removes an attribute from an element.

#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

備註

如果已移除的屬性已知有預設值, 則會立即出現屬性, 其中包含預設值, 以及對應的命名空間 URI、區功能變數名稱稱和前置詞 (如果適用的話)。If the removed attribute is known to have a default value, an attribute immediately appears containing the default value and, if applicable, the corresponding namespace URI, local name, and prefix.

適用於