XmlElement.RemoveAttributeNode 方法

定義

移除 XmlAttribute

多載

RemoveAttributeNode(XmlAttribute)

移除指定的 XmlAttribute

RemoveAttributeNode(String, String)

移除區域名稱和命名空間 URI 指定的 XmlAttribute (如果移除的屬性具有預設值,則會立即予以取代)。

RemoveAttributeNode(XmlAttribute)

移除指定的 XmlAttribute

C#
public virtual System.Xml.XmlAttribute RemoveAttributeNode (System.Xml.XmlAttribute oldAttr);
C#
public virtual System.Xml.XmlAttribute? RemoveAttributeNode (System.Xml.XmlAttribute oldAttr);

參數

oldAttr
XmlAttribute

要移除的 XmlAttribute 節點。 如果移除的屬性具預設值,會立即被取代。

傳回

XmlAttribute

移除的 XmlAttribute;如果 oldAttr 不是 null 的屬性節點,則為 XmlElement

例外狀況

這個節點是唯讀的。

適用於

.NET 7 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1
UWP 10.0

RemoveAttributeNode(String, String)

移除區域名稱和命名空間 URI 指定的 XmlAttribute (如果移除的屬性具有預設值,則會立即予以取代)。

C#
public virtual System.Xml.XmlAttribute RemoveAttributeNode (string localName, string namespaceURI);
C#
public virtual System.Xml.XmlAttribute? RemoveAttributeNode (string localName, string? namespaceURI);

參數

localName
String

屬性的本機名稱。

namespaceURI
String

屬性的命名空間 URI。

傳回

XmlAttribute

移除的 XmlAttribute;如果 null 沒有相符的屬性節點,則為 XmlElement

例外狀況

這個節點是唯讀的。

範例

下列範例會從 專案中移除 屬性。

C#
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.RemoveAttributeNode("ISBN", "urn:samples");

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

適用於

.NET 7 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1
UWP 10.0