XElement.ReplaceAttributes 方法

定義

以指定的內容取代這個元素的屬性。

多載

ReplaceAttributes(Object[])

以指定的內容取代這個元素的屬性。

ReplaceAttributes(Object)

以指定的內容取代這個元素的屬性。

範例

下列範例會建立具有三個屬性的專案。 然後,它會使用這個方法,以單一屬性取代 專案的所有屬性。

XElement root = new XElement("Root",
    new XAttribute("Att1", 1),
    new XAttribute("Att2", 2),
    new XAttribute("Att3", 3)
);
root.ReplaceAttributes(
    new XAttribute("NewAtt1", 101)
);
Console.WriteLine(root);
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3"/>
root.ReplaceAttributes(New XAttribute("NewAtt1", 101))
Console.WriteLine(root)

這個範例會產生下列輸出:

<Root NewAtt1="101" />

備註

這個方法會引發 ChangedChanging 事件。

如需可以傳遞至此函式之有效內容的詳細資訊,請參閱 XElement 和 XDocument 物件的有效內容

ReplaceAttributes(Object[])

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

以指定的內容取代這個元素的屬性。

public:
 void ReplaceAttributes(... cli::array <System::Object ^> ^ content);
public void ReplaceAttributes (params object[] content);
public void ReplaceAttributes (params object?[] content);
member this.ReplaceAttributes : obj[] -> unit
Public Sub ReplaceAttributes (ParamArray content As Object())

參數

content
Object[]

內容物件的參數清單。

範例

下列範例會建立具有三個屬性的專案。 然後,它會以其他屬性取代屬性。

XElement root = new XElement("Root",
    new XAttribute("Att1", 1),
    new XAttribute("Att2", 2),
    new XAttribute("Att3", 3)
);
root.ReplaceAttributes(
    new XAttribute("NewAtt1", 101),
    new XAttribute("NewAtt2", 102),
    new XAttribute("NewAtt3", 103)
);
Console.WriteLine(root);
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3"/>
root.ReplaceAttributes( _
New XAttribute("NewAtt1", 101), _
New XAttribute("NewAtt2", 102), _
New XAttribute("NewAtt3", 103))
Console.WriteLine(root)

這個範例會產生下列輸出:

<Root NewAtt1="101" NewAtt2="102" NewAtt3="103" />

備註

這個方法會先移除現有的屬性。 然後,它會新增指定的 content

如需可以傳遞至此函式之有效內容的詳細資訊,請參閱 XElement 和 XDocument 物件的有效內容

這個方法會引發 ChangedChanging 事件。

另請參閱

適用於

ReplaceAttributes(Object)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

以指定的內容取代這個元素的屬性。

public:
 void ReplaceAttributes(System::Object ^ content);
public void ReplaceAttributes (object content);
public void ReplaceAttributes (object? content);
member this.ReplaceAttributes : obj -> unit
Public Sub ReplaceAttributes (content As Object)

參數

content
Object

將取代這個元素之屬性的內容。

範例

下列範例會建立具有三個屬性的專案。 然後,它會使用這個方法,以單一屬性取代 專案的所有屬性。

XElement root = new XElement("Root",
    new XAttribute("Att1", 1),
    new XAttribute("Att2", 2),
    new XAttribute("Att3", 3)
);
root.ReplaceAttributes(
    new XAttribute("NewAtt1", 101)
);
Console.WriteLine(root);
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3"/>
root.ReplaceAttributes(New XAttribute("NewAtt1", 101))
Console.WriteLine(root)

這個範例會產生下列輸出:

<Root NewAtt1="101" />

備註

這個方法會先移除現有的屬性。 然後,它會新增指定的 content

如需可以傳遞至此函式之有效內容的詳細資訊,請參閱 XElement 和 XDocument 物件的有效內容

這個方法會引發 ChangedChanging 事件。

另請參閱

適用於