XmlElement.SetAttribute XmlElement.SetAttribute XmlElement.SetAttribute XmlElement.SetAttribute Method

定義

設定指定屬性的值。Sets the value of the specified attribute.

多載

SetAttribute(String, String) SetAttribute(String, String) SetAttribute(String, String) SetAttribute(String, String)

設定具有指定名稱之屬性的值。Sets the value of the attribute with the specified name.

SetAttribute(String, String, String) SetAttribute(String, String, String) SetAttribute(String, String, String) SetAttribute(String, String, String)

設定具有指定區域名稱和命名空間 URI 之屬性的值。Sets the value of the attribute with the specified local name and namespace URI.

SetAttribute(String, String) SetAttribute(String, String) SetAttribute(String, String) SetAttribute(String, String)

設定具有指定名稱之屬性的值。Sets the value of the attribute with the specified name.

public:
 virtual void SetAttribute(System::String ^ name, System::String ^ value);
public virtual void SetAttribute (string name, string value);
abstract member SetAttribute : string * string -> unit
override this.SetAttribute : string * string -> unit
Public Overridable Sub SetAttribute (name As String, value As String)

參數

name
String String String String

要建立或變更的屬性的名稱。The name of the attribute to create or alter. 這是限定名稱。This is a qualified name. 如果名稱包含冒號,將會剖析為前置詞和區域名稱元件。If the name contains a colon it is parsed into prefix and local name components.

value
String String String String

要為屬性設定的值。The value to set for the attribute.

例外狀況

指定的名稱包含無效的字元。The specified name contains an invalid character.

節點為唯讀。The node is read-only.

備註

如果專案中已經有相同名稱的屬性, 其值會變更為valueIf an attribute with the same name is already present in the element, its value is changed to that of value. value是簡單的字串。value is a simple string. 它在設定時不會剖析。It is not parsed as it is being set. 任何標記 (例如要辨識為實體參考的語法) 都會被視為常值文字, 而且必須在寫出時由實作為正確的轉義。若要指派包含實體參考的屬性值, 使用者必須XmlAttribute建立節點加上任何XmlTextXmlEntityReference節點、建立適當的子樹, 並使用SetAttributeNode將它指派為屬性的值。Any markup, such as syntax to be recognized as an entity reference, is treated as literal text and needs to be properly escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create an XmlAttribute node plus any XmlText and XmlEntityReference nodes, build the appropriate subtree and use SetAttributeNode to assign it as the value of an attribute.

SetAttribute(String, String, String) SetAttribute(String, String, String) SetAttribute(String, String, String) SetAttribute(String, String, String)

設定具有指定區域名稱和命名空間 URI 之屬性的值。Sets the value of the attribute with the specified local name and namespace URI.

public:
 virtual System::String ^ SetAttribute(System::String ^ localName, System::String ^ namespaceURI, System::String ^ value);
public virtual string SetAttribute (string localName, string namespaceURI, string value);
abstract member SetAttribute : string * string * string -> string
override this.SetAttribute : string * string * string -> string
Public Overridable Function SetAttribute (localName As String, namespaceURI As String, value As String) As String

參數

localName
String String String String

屬性的本機名稱。The local name of the attribute.

namespaceURI
String String String String

屬性的命名空間 URI。The namespace URI of the attribute.

value
String String String String

要為屬性設定的值。The value to set for the attribute.

傳回

屬性值。The attribute value.

適用於