【问题标题】:Get string form XML file by attribute通过属性从 XML 文件中获取字符串
【发布时间】:2014-04-28 08:56:00
【问题描述】:

我有一个 XML 文件

<resources>
  <string name="aaa">Hotel</string>
  <string name="bbb">Home</string>
  <string name="ccc">Castle</string>
  ...
<resourses>

我尝试使用特殊名称(aaa, bbb ..)获取内容字符串(Hotel 或 Home ...)。

【问题讨论】:

标签: c# windows-phone-7 windows-phone-8 nsxmlparser


【解决方案1】:
var xml = XDocument.Parse(yourxmlstring, LoadOptions.None);
var resources= xml.Descendants("resources");
foreach (var resourceElement in resources.Descendants("Hotel"))
{
    MessageBox.Show(resourceElement.Attribute("name").Value);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多