XElement.ReplaceAttributes 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将此元素的属性替换为指定的内容。
重载
| 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" />
	注解
有关可传递给此函数的有效内容的详细信息,请参阅 XElement 和 XDocument 对象的有效内容。
ReplaceAttributes(Object[])
- Source:
 - XElement.cs
 
- 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 对象的有效内容。
另请参阅
适用于
ReplaceAttributes(Object)
- Source:
 - XElement.cs
 
- 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 对象的有效内容。