简体   繁体   English

如何使用LINQ,C#向元素添加属性?

[英]How to add attributes to an element using LINQ, C#?

I have an XElement object which has a number of attributes and I simply want to add another attribute to the element. 我有一个XElement对象,它有许多属性,我只想在元素中添加另一个属性。

How do I do this? 我该怎么做呢?

xElement.Add(new XAttribute("Foo", "Bar"));

要创建具有属性的元素,请使用:
var xmlTest = new XElement("XmlElementName", new XAttribute("XmlAttributeName", "AttributeValue"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM