Good Day,
I have been playing with the ToDicationary() extension method
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);
}
with the following XML data:
<?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>
and I'm not getting the output I want. Instead I'm getting this:
Writing music...
AlbumDetails = Ottmar LiebertBarcelona NightsSpain
Instead, I want myData("Artist") = "Ottmar Liebert", etc...
Is it possible to do with Descendants?
TIA,
coson
AlbumDetails's descendants. Artist,Song,Origin might happen not to be unique.