我一直在尝试根据元素将下载的xml字符串转换为Lists,但我似乎无法找到解决方案。 我的目标是获得艺术家的名字。
以下是xml页面的摘录:
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.10.2">
<artists ignoredArticles="The El La Los Las Le Les">
<index name="A">
<artist id="15" name="A Tribe Called Quest" coverArt="ar-15" albumCount="5"/>
<artist id="2" name="A$AP Ferg" coverArt="ar-2" albumCount="1"/>
<artist id="11" name="A$ap Mob" coverArt="ar-11" albumCount="1"/>
<artist id="353" name="A$AP Rocky" coverArt="ar-353" albumCount="3"/>
<artist id="382" name="A-1" coverArt="ar-382" albumCount="3"/>
<artist id="9" name="A1 Bassline & Rusko" coverArt="ar-9" albumCount="1"/>
<artist id="25" name="Aaliyah" coverArt="ar-25" albumCount="7"/>
<artist id="1" name="Ab-Soul" coverArt="ar-1" albumCount="4"/>
<artist id="50" name="Ace Hood" coverArt="ar-50" albumCount="18"/>
<artist id="134" name="Adele" coverArt="ar-134" albumCount="4"/>
<artist id="283" name="Aesop Rock & Del Tha Funky Homosapien" coverArt="ar-283" albumCount="1"/>
<artist id="92" name="Afroman" coverArt="ar-92" albumCount="10"/>
<artist id="280" name="Akinyele" albumCount="1"/>
<artist id="421" name="Akira Kosemura" albumCount="1"/>
<artist id="163" name="Akon" coverArt="ar-163" albumCount="20"/>
<artist id="152" name="Akon, T-pain" albumCount="1"/>
<artist id="106" name="All Saints" coverArt="ar-106" albumCount="1"/>
<artist id="287" name="Almighty" coverArt="ar-287" albumCount="1"/>
<artist id="176" name="Amanda Blank" coverArt="ar-176" albumCount="1"/>
<artist id="56" name="ASIAN KUNG-FU GENERATION" coverArt="ar-56" albumCount="6"/>
<artist id="374" name="Atmosphere" albumCount="11"/>
<artist id="105" name="Attaca Pesante" coverArt="ar-105" albumCount="1"/>
<artist id="190" name="Audio Bullys" coverArt="ar-190" albumCount="1"/>
<artist id="44" name="August Alsina" coverArt="ar-44" albumCount="1"/>
</index>
<index name="B">
答案 0 :(得分:4)
这是我的想法,但您必须先创建列表“名称”。试试这个:
XDocument xDoc = XDocument.Load("your xml file");
foreach (var elem in xDoc.Document.Descendants("artist"))
{
names.Add(elem.Attribute("name").Value);
}