再会,
我一直在玩 ToDicationary() 扩展方法
var document = XDocument.Load(@"..\..\Info.xml");
XNamespace ns = "http://www.someurl.org/schemas";
var myData = document.Descendants(ns + "AlbumDetails").ToDictionary
(
e => e.Name.LocalName.ToString(),
e => e.Value
);
Console.WriteLine("Writing music...");
foreach (KeyValuePair<string, string> kvp in myData)
{
Console.WriteLine("{0} = {1}", kvp.Key, kvp.Value);
}
使用以下 XML 数据:
<?xml version="1.0" encoding="UTF-8"?>
<Database xmlns="http://www.someurl.org/schemas">
<Info>
<AlbumDetails>
<Artist>Ottmar Liebert</Artist>
<Song>Barcelona Nights</Song>
<Origin>Spain</Origin>
</AlbumDetails>
</Info>
</Database>
而且我没有得到我想要的输出。相反,我得到了这个:
Writing music...
AlbumDetails = Ottmar LiebertBarcelona NightsSpain
相反,我想要 myData("Artist") = "Ottmar Liebert" 等...
有没有可能与后代有关?
TIA,
科森