Editare

Partajați prin


XElement.ReplaceAttributes Method

Definition

Replaces the attributes of this element with the specified content.

Overloads

ReplaceAttributes(Object[])

Replaces the attributes of this element with the specified content.

ReplaceAttributes(Object)

Replaces the attributes of this element with the specified content.

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.

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)

This example produces the following output:

<Root NewAtt1="101" />

Remarks

This method will raise the Changed and the Changing events.

For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

ReplaceAttributes(Object[])

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

Replaces the attributes of this element with the specified content.

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())

Parameters

content
Object[]

A parameter list of content objects.

Examples

The following example creates an element with three attributes. It then replaces the attributes with other attributes.

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)

This example produces the following output:

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

Remarks

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

For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

This method will raise the Changed and the Changing events.

See also

Applies to

ReplaceAttributes(Object)

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

Replaces the attributes of this element with the specified content.

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)

Parameters

content
Object

The content that will replace the attributes of this element.

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.

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)

This example produces the following output:

<Root NewAtt1="101" />

Remarks

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

For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

This method will raise the Changed and the Changing events.

See also

Applies to