【问题标题】:How to loop through all XElement attributes and get their values如何遍历所有 XElement 属性并获取它们的值
【发布时间】:2012-05-10 18:25:56
【问题描述】:

如何遍历所有 XElement 属性并获取它们的值?

foreach (SyndicationElementExtension extension in f.ElementExtensions)
{
    XElement element = extension.GetObject<XElement>();

    // How to loop through all its attributes and get their values?
}

谢谢!

【问题讨论】:

    标签: c# xml xpath


    【解决方案1】:

    简单——使用Attributes()方法:

    foreach (var attribute in element.Attributes())
    {
        string value = attribute.Value;
        // ...
    }
    

    【讨论】:

      【解决方案2】:

      假设您想回复this question

      var img2 = feeds.Items
           .SelectMany(i => i.ElementExtensions
                             .Select(e => e.GetObject<XElement>().Attribute("url").Value)
                      )
           .ToArray();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-16
        相关资源
        最近更新 更多