XElement.ReplaceAttributes メソッド

定義

この要素の属性を、指定された内容で置き換えます。

オーバーロード

ReplaceAttributes(Object[])

この要素の属性を、指定された内容で置き換えます。

ReplaceAttributes(Object)

この要素の属性を、指定された内容で置き換えます。

次の例では、3 つの属性を持つ 要素を作成します。 次に、このメソッドを使用して、 要素のすべての属性を 1 つの属性に置き換えます。

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" />

注釈

このメソッドは、 イベントと イベントをChanging発生させますChanged

この関数に渡すことができる有効なコンテンツの詳細については、「 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[]

コンテンツ オブジェクトのパラメーター リスト。

次の例では、3 つの属性を持つ 要素を作成します。 次に、属性を他の属性に置き換えます。

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 オブジェクトの有効なコンテンツ」を参照してください。

このメソッドは、 イベントと イベントをChanging発生させますChanged

こちらもご覧ください

適用対象

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

この要素の属性を置き換える内容。

次の例では、3 つの属性を持つ 要素を作成します。 次に、このメソッドを使用して、 要素のすべての属性を 1 つの属性に置き換えます。

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 オブジェクトの有効なコンテンツ」を参照してください。

このメソッドは、 イベントと イベントをChanging発生させますChanged

こちらもご覧ください

適用対象