【问题标题】:Can I read XML Attributes dynamically in WPF C#我可以在 WPF C# 中动态读取 XML 属性吗
【发布时间】:2014-05-28 03:29:39
【问题描述】:

您好,我非常担心读取 XML 属性,例如

<xmlNode attribute1="somevalue1" attribute2="somevalue2" attribute3="somevalue3">

我们可以动态读取attribiute1、attribute2或attribute3吗?我知道我们可以通过nd.Attributes["attribiute1"].Value 读取属性值。但是如何动态读取这个“attribute1”?

【问题讨论】:

  • 类似foreach (XmlAttribute attribute in nd.Attributes)?
  • 你试过Attributes[index]吗?
  • dynamically.. 是指谁?
  • @Adriano 是什么让它充满活力?
  • 解释您所说的“动态”是什么意思,以便我们尝试提供帮助。

标签: c# xml wpf


【解决方案1】:
var xml = XElement.Parse(@"your xml");
foreach (var attr in xml.Attributes())
{

}

这不是 WPF 特有的,它适用于您可以访问 linq to xml 提供程序的任何地方

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-12
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多