XmlElement.RemoveAttribute メソッド

定義

指定した属性を削除します。 (削除された属性に既定値がある場合は、すぐに置き換えられます)。

オーバーロード

名前 説明
RemoveAttribute(String)

名前で属性を削除します。

RemoveAttribute(String, String)

指定したローカル名と名前空間 URI を持つ属性を削除します。 (削除された属性に既定値がある場合は、すぐに置き換えられます)。

RemoveAttribute(String)

ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs

名前で属性を削除します。

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;
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)

ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs

指定したローカル名と名前空間 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;
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、ローカル名、プレフィックスが表示されます。

適用対象