我有一个类似这样的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<resource key="123">foo</resource>
<resource key="456">bar</resource>
<resource key="789">bar</resource>
</data>
我想把它作为键值对放入字典(排序)中。 IE: 123:富, 456:酒吧...等等
key 未知。
我该怎么做?
最佳答案
这看起来像是 Linq to Xml 的工作
static void Main(string[] args)
{
XDocument yourDoc = XDocument.Load("the.xml");
var q = from c in yourDoc.Descendants("resource")
orderby (int) c.Attribute("key")
select c.Attribute("key").Value + ":" + c.Value;
foreach (string s in q)
Console.WriteLine(s);
Console.ReadLine();
}
关于c# - 将 xml 转换为排序字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/653540/