XmlElement.RemoveAttributeAt(Int32) XmlElement.RemoveAttributeAt(Int32) XmlElement.RemoveAttributeAt(Int32) XmlElement.RemoveAttributeAt(Int32) Method

定義

移除項目中具有指定索引的屬性節點Removes the attribute node with the specified index from the element. (如果移除的屬性具有預設值,會立即被取代)。(If the removed attribute has a default value, it is immediately replaced).

public:
 virtual System::Xml::XmlNode ^ RemoveAttributeAt(int i);
public virtual System.Xml.XmlNode RemoveAttributeAt (int i);
abstract member RemoveAttributeAt : int -> System.Xml.XmlNode
override this.RemoveAttributeAt : int -> System.Xml.XmlNode
Public Overridable Function RemoveAttributeAt (i As Integer) As XmlNode

參數

i
Int32 Int32 Int32 Int32

要移除的節點的索引。The index of the node to remove. 第一個節點的索引為 0。The first node has index 0.

傳回

移除的屬性節點;如果指定的索引中沒有節點,則為 nullThe attribute node removed or null if there is no node at the given index.

範例

下列範例會從元素移除屬性。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->RemoveAttributeAt( 0 );
   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.RemoveAttributeAt(0);
    
    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.RemoveAttributeAt(0)

    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

備註

這個方法是檔物件模型 (DOM) 的 Microsoft 擴充功能。This method is a Microsoft extension to the Document Object Model (DOM).

適用於