0

我知道 MusicBrainz 有可用的版本 2,但 v1 是我做到这一点的唯一方法。(这是 1 个返回,通常是数百个......): XML:

<metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#" xmlns:ext="http://musicbrainz.org/ns/ext-1.0#">
   <release-list count="928" offset="0">
      <release id="bea5602c-53bc-4416-af49-238aae51e8ea" type="Live Bootleg" ext:score="100">
         <title>Seattle 1988</title>
         <text-representation language="ENG" script="Latn" />
         <artist id="5b11f4ce-a62d-471e-81fc-a69a8278c7da">
            <name>Nirvana</name>
            <sort-name>Nirvana</sort-name>
         </artist>
         <release-event-list>
            <event format="CD" />
         </release-event-list>
         <disc-list count="0" />
         <track-list count="10" />
      </release>
   </release-list>
</metadata>

我可以通过以下方式返回所有专辑:

client = new WebClient();
        client.OpenReadCompleted += client_OpenReadCompleted;
        // Call public web service.
        string requestUri =
        "http://musicbrainz.org/ws/1/release/?limit=100&type=xml&artist={0}";
        client.OpenReadAsync(
          new Uri(String.Format(
          requestUri, "Jimi Hendrix")));

 private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
          // Process returned data.
        XElement results;
        albums = new List<string>();

        if (e.Error != null)
        { return; }
        else
        {
            XNamespace ns =
            @"http://musicbrainz.org/ns/mmd-1.0#";
            results = XElement.Load(e.Result);

            var q = from r in results.Descendants(ns + "release")
                    select new { Title = r.Element(ns + "title").Value };

            foreach (var i in q)
            {
                albums.Add(i.Title);
                Console.WriteLine(i.Title);
            }
        }

我怎样才能获得每张专辑的发行ID?

4

3 回答 3

0

由于您已经选择了发布节点,您只需要获取该id-attribute:

var q = from r in results.Descendants(ns + "release")
        select new 
        { 
            Title = r.Element(ns + "title").Value, 
            Release = r.Attribute("id").Value 
        };
于 2015-01-26T18:15:41.523 回答
0

这里是你可以用来存储数据的类

class Release 
{
    public Guid Id {get; set;}
    public string Title {get; set;}
}

这就是您可以Release从响应中检索集合的方式。

XNamespace ns = "http://musicbrainz.org/ns/mmd-1.0#";
var doc = XElement.Load(e.Result);

IEnumerable<Release> res = doc.Descendants(ns + "release")
      .Select(r => new Release{
                                 Id = (Guid)r.Attribute("id"),
                                 Title = (string)r.Element(ns + "title")
                              });
于 2015-01-26T18:23:22.593 回答
0
var q = from r in results.Descendants(ns + "release")
    select new 
    { 
        Title = r.Element(ns + "title").Value, 
        Release = r.Attribute("id").Value 
    };

效果很好!谢谢

于 2015-01-26T18:23:23.760 回答