【问题标题】:How to add attributes to an element using LINQ, C#?如何使用 LINQ、C# 向元素添加属性?
【发布时间】:2010-03-16 12:48:51
【问题描述】:

我有一个 XElement 对象,它有许多属性,我只是想为元素添加另一个属性。

我该怎么做?

【问题讨论】:

    标签: c# xml linq


    【解决方案1】:
    xElement.Add(new XAttribute("Foo", "Bar"));
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-05
        • 1970-01-01
        • 2020-12-29
        • 2011-12-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多