Share via


XElement.ReplaceAttributes Method (Object)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Replaces the attributes of this element with the specified content.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

Syntax

'Declaration
Public Sub ReplaceAttributes ( _
    content As Object _
)
public void ReplaceAttributes(
    Object content
)

Parameters

  • content
    Type: System.Object
    The content that will replace the attributes of this element.

Remarks

This method first removes existing attributes. It then adds the specified content.

For more information about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects in the .NET Framework documentation.

This method will raise the Changed and the Changing events.

Examples

The following example creates an element with three attributes. It then uses this method to replace all of the attributes of the element with a single attribute.

Dim output As New StringBuilder
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3"/>
root.ReplaceAttributes(New XAttribute("NewAtt1", 101))
output.Append(root)
output.Append(Environment.NewLine)

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
XElement root = new XElement("Root",
    new XAttribute("Att1", 1),
    new XAttribute("Att2", 2),
    new XAttribute("Att3", 3)
);
root.ReplaceAttributes(
    new XAttribute("NewAtt1", 101)
);
output.Append(root + Environment.NewLine);

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.