i have a .xspf playlist that i parse but the playlist has folders inside folders so when i display my parsed data
it doesnt have the same "depth". what would be the best way to achieve this.
Here is the .xspf
the folders are <vlc:node title="FOLDER">
<?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/JD/New%20Folder%20%282%29/Uuskaial.mp4</location><duration>1267008</duration><extension application="http://www.videolan.org/vlc/playlist/0"><vlc:id>0</vlc:id></extension></track><track><location>file:///E:/Downloads/JD/New%20Folder%20%282%29/Uusi%20kansio/111acho.mp4</location><duration>1904013</duration><extension application="http://www.videolan.org/vlc/playlist/0"><vlc:id>1</vlc:id></extension></track><track><location>file:///E:/Downloads/JD/New%20Folder%20%282%29/Uuansio.mp4</location><duration>538800</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"><vlc:node title="444"><vlc:item tid="157"/><vlc:item tid="158"/><vlc:item tid="159"/><vlc:item tid="160"/><vlc:item tid="161"/><vlc:item tid="162"/><vlc:item tid="163"/><vlc:item tid="164"/><vlc:item tid="165"/><vlc:item tid="166"/><vlc:item tid="167"/><vlc:item tid="168"/><vlc:item tid="169"/><vlc:item tid="170"/><vlc:item tid="171"/><vlc:item tid="172"/><vlc:item tid="173"/><vlc:item tid="174"/><vlc:item tid="175"/></vlc:node><vlc:node title="333"><vlc:node title="em"><vlc:item tid="215"/><vlc:item tid="216"/><vlc:item tid="217"/><vlc:item tid="218"/><vlc:item tid="219"/><vlc:item tid="220"/></vlc:node><vlc:node title="soo"><vlc:item tid="236"/><vlc:item tid="237"/><vlc:item tid="238"/><vlc:item tid="239"/></vlc:node><vlc:node title="WC"><vlc:item tid="269"/><vlc:item tid="270"/><vlc:item tid="271"/><vlc:item tid="272"/><vlc:item tid="273"/><vlc:item tid="274"/><vlc:item tid="275"/><vlc:item tid="276"/><vlc:item tid="277"/><vlc:item tid="278"/><vlc:item tid="279"/></vlc:node><vlc:node title="1"><vlc:node title="12"><vlc:item tid="319"/><vlc:item tid="320"/><vlc:item tid="321"/><vlc:item tid="322"/><vlc:item tid="323"/><vlc:item tid="324"/><vlc:item tid="325"/><vlc:item tid="326"/><vlc:item tid="327"/><vlc:item tid="328"/></vlc:node><vlc:item tid="371"/><vlc:item tid="372"/><vlc:item tid="373"/><vlc:item tid="374"/><vlc:item tid="375"/><vlc:item tid="376"/><vlc:item tid="377"/><vlc:item tid="378"/><vlc:item tid="379"/><vlc:item tid="380"/></vlc:node><vlc:item tid="439"/><vlc:item tid="440"/><vlc:item tid="441"/><vlc:item tid="442"/><vlc:item tid="443"/><vlc:item tid="444"/></vlc:node></extension></playlist>
Here is the c# code
private void button4_Click(object sender, EventArgs e) { XDocument xdoc = XDocument.Load("aaah.xspf"); XElement playlist = (XElement)xdoc.FirstNode; XNamespace ns = xdoc.Root.GetDefaultNamespace(); XNamespace nx = ("http://www.videolan.org/vlc/playlist/ns/0/"); var extension = xdoc.Root.Element(ns + "extension"); var nodes = extension.Descendants(nx + "node").Where(n => n.Elements(nx + "item").Any()); List<TitleAndIds> titles = nodes.Select(n => new TitleAndIds { Title = n.Attribute("title").Value, Ids = n.Elements(nx + "item").Select(i => int.Parse(i.Attribute("tid").Value)).ToArray() }).ToList(); 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 titles) { treeView1.Nodes.Add(new TreeNode(item.Title)); foreach (var childItem in item.Ids) { //Remove %20 (spaces) var file = System.Net.WebUtility.UrlDecode(fileSignatures[childItem].location); //trim file:/// from start char[] trimChar = { 'f', 'i', 'l', 'e', '/', ':' }; file = file.TrimStart(trimChar); //treeView1.Nodes[titles.IndexOf(item)].Nodes.Add(new TreeNode(childItem.ToString())); treeView1.Nodes[titles.IndexOf(item)].Nodes.Add(new TreeNode(file)); } } }
Thanks