SecurityElement.AddAttribute(String, String) 方法

定義

在 XML 元素中加入名稱/值屬性。

public:
 void AddAttribute(System::String ^ name, System::String ^ value);
public void AddAttribute(string name, string value);
member this.AddAttribute : string * string -> unit
Public Sub AddAttribute (name As String, value As String)

參數

name
String

屬性的名稱。

value
String

屬性的值。

例外狀況

參數namevalue或參數為 null

name value參數或參數在 XML 中是無效的。

-或-

已經有一個由參數指定的 name 屬性名稱。

範例

以下程式碼展示了如何使用此 AddAttribute 方法為 XML 元素加入名稱/值屬性。 此程式碼範例是本類別更大範例 SecurityElement 的一部分。

windowsRoleElement.AddAttribute("version","1.00");
windowsRoleElement.AddAttribute("version", "1.00")

備註

屬性中的名稱與值應僅包含有效的 XML 屬性字元。 XML 屬性名稱必須是唯一的。 用於 Escape 移除字串中的無效字元。

目前不支援引號字串,因此名稱/值對的字串不應包含引號或其他需要引用的字元。

適用於