XmlElement.RemoveAttribute 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
移除指定的特性。 (如果删除的特性具有默认值时,则将立即替换它)。
重载
| RemoveAttribute(String) | 
						   按名称删除特性。  | 
        	
| RemoveAttribute(String, String) | 
						   移除具有指定本地名称和命名空间 URI 的特性。 (如果删除的特性具有默认值时,则将立即替换它)。  | 
        	
RemoveAttribute(String)
按名称删除特性。
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
 
要移除的属性的名称。 这是限定名。 它针对匹配节点的 Name 属性进行匹配。
例外
该节点是只读的。
示例
以下示例从元素中删除属性。
#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、本地名称和前缀。
适用于
RemoveAttribute(String, String)
移除具有指定本地名称和命名空间 URI 的特性。 (如果删除的特性具有默认值时,则将立即替换它)。
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)
	参数
- localName
 - String
 
要移除的特性的本地名称。
- namespaceURI
 - String
 
要移除的特性的命名空间 URI。
例外
该节点是只读的。
示例
以下示例从元素中删除属性。
#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、本地名称和前缀。