我需要获取“标题”(文件夹)属性的值以及播放列表中每个标题中的所有“tid”(id)数字是.xspf
<?xml version="1.0" encoding="UTF-8"?>
<playlist xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/" version="1">
<title>Playlist</title>
<trackList>
<track>
<location>file:///E:/Downloads/video1.mp4</location>
<duration>681493</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>0</vlc:id>
</extension>
</track>
<track>
<location>file:///E:/Downloads/video2.mp4</location>
<duration>614585</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>1</vlc:id>
</extension>
</track>
<track>
<location>file:///E:/Downloads/video3.mp4</location>
<duration>220629</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>2</vlc:id>
</extension>
</track>
</trackList>
<extension application="http://www.videolan.org/vlc/playlist/0" xmlns="http://xspf.org/ns/0/">
<vlc:node title="oooh11111.xspf" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/">
<vlc:node title="BillyJ">
<vlc:item tid="0" />
<vlc:item tid="1" />
<vlc:item tid="2" />
<vlc:item tid="3" />
<vlc:item tid="4" />
<vlc:item tid="5" />
<vlc:item tid="6" />
<vlc:item tid="7" />
<vlc:item tid="8" />
<vlc:item tid="9" />
<vlc:item tid="10" />
<vlc:item tid="57" />
<vlc:item tid="58" />
<vlc:item tid="59" />
</vlc:node>
<vlc:node title="Solo">
<vlc:item tid="60" />
<vlc:item tid="61" />
<vlc:item tid="62" />
<vlc:item tid="63" />
<vlc:item tid="64" />
<vlc:item tid="65" />
<vlc:item tid="66" />
<vlc:item tid="67" />
<vlc:item tid="102" />
<vlc:item tid="103" />
<vlc:item tid="104" />
</vlc:node>
<vlc:node title="Best">
<vlc:item tid="105" />
<vlc:item tid="106" />
<vlc:item tid="107" />
<vlc:item tid="108" />
<vlc:item tid="109" />
<vlc:item tid="110" />
<vlc:item tid="111" />
</vlc:node>
</extension>
</playlist>
但现在我需要获取每个标题中“标题”(文件夹)属性和所有“tid”(id)数字的值:
BillyJ
0
1
2
3
4
5
...
独奏
60
61
62
63
64
...
所以我可以通过它们的 id 将文件排序到文件夹
这是我解析位置持续时间和 id 的方法:
class PlaylistItem
{
public string location { get; set; }
public string extensions { get; set; }
public string duration { get; set; }
}
private void button2_Click(object sender, EventArgs e)
{
XDocument xdoc = XDocument.Load(@"1.xspf");
XNamespace ns = ((XElement)xdoc.FirstNode).Name.Namespace;
XNamespace nx = ("http://www.videolan.org/vlc/playlist/ns/0/");
List<PlaylistItem> fileSignatures = (from file in xdoc.Descendants(ns+ "track")
select new PlaylistItem
{
location = (string)file.Element(ns + "location").Value,
extensions = (string)file.Element(ns + "extension").Value,
duration = (string)file.Element(ns + "duration")
}).ToList();
foreach (var item in fileSignatures)
{
if (item.duration != null)
{
//Remove %20 (spaces)
var file = System.Net.WebUtility.UrlDecode(item.location);
//trim file:/// from start
char[] trimChar = { 'f', 'i', 'l', 'e','/',':' };
file = file.TrimStart(trimChar);
listBox1.Items.Add("Duration: " + item.duration + " id: " + item.extensions);
listBox1.Items.Add("File: " + file);
}
else
{
}
}
}