Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 2 of 2

Thread: Stuck in XML

  1. #1
    Join Date
    Nov 2005
    Location
    Banned by moderator.
    Posts
    264

    Grin Stuck in XML

    For the first time, I'm stuck in XML. I have a long code to save a playlist. I attached it, because is too big. For some reason, I get an error...Failed to insert XML or something like that (I used the debug windows). I also attached the project, it may help. Thanks
    Attached Files

  2. #2
    Join Date
    Nov 2005
    Location
    Banned by moderator.
    Posts
    264
    I corrected that error, but I found 2 more errors with XML. First, the LoadPlaylist function wil add only 1 item in the playlist (xml part). Second, SavePlaylist will only save the last file in the ListBox (xml part). Any ideas?

    Code:
    function LoadPlaylist()
    
    -- ask for the path of the playlist and load it
    	FilePath = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "M3U Playlist|*.m3u|XML Playlist|*.xml|", nil, nil, false, true);
    -- make sure that cancel was not pressed
    if FilePath[1] ~= "CANCEL" then
    -- find the extension
    	ext = String.SplitPath(FilePath[1]).Extension;
    -- if it's m3u, it's a text file
    if ext == ".m3u" then
    -- read the contents
    	play_file = TextFile.ReadToTable(FilePath[1]);
    -- make sure it's not empty
    if play_file ~= nil then
    for j,Path in play_file do
    -- get the file name and add it to the playlist
    	file_name = String.SplitPath(Path).Filename;
    	ListBox.AddItem("Playlist", file_name, Path);
    end
    end
    -- if it's xml, it's a complex file
    elseif ext == ".xml" then
    -- something needed
    if i == nil then
    i = 0
    end
    -- load the xml
    	XML.Load(FilePath[1]);
    -- get the value
    	j = i+1
    	i = j
    	data = XML.GetValue("*/file"..j);
    -- make sure it's not empty
    if data ~= nil then
    -- get the file name and add it to the playlist
    	file_name = String.SplitPath(data).Filename;
    	ListBox.AddItem("Playlist", file_name, data);
    end
    end
    end
    end
    
    -- ******** Another funtion ********
    
    function SavePlaylist()
    
    -- ask for the folder
    	PlayListFolder = Dialog.FolderBrowse("Please select the folder where your M3U playlist will be saved", _DesktopFolder);
    if PlayListFolder ~= "CANCEL" then
    -- ask what type of playlist
    	type = Dialog.Message("XML?", "Do you want the playlist to be XML or M3U? For XML press YES, for M3U press NO.", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
    if type ~= 6 then
    -- do what's needed
    	FolderFound = Folder.DoesExist(PlayListFolder);
    	PlayList = nil;
    	Files = ListBox.GetCount("Playlist");
    if Files == 0 then
    -- say if the playlist is empty
    	Dialog.Message("Notice", "The playlist is empty.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    else
    -- ask for the file name
    	PlayList = Dialog.Input("Please enter the file name.", "File Name:", nil, MB_ICONQUESTION);
    	PlayListFound = File.DoesExist(PlayListFolder.."\\"..PlayList..".m3u");
    if PlayListFound == true then
    -- say if the playlist can be overwritten
    	proceed = Dialog.Message("Notice", "The playlist is not empty. Do you want to overwrite?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
    if proceed == IDYES then
    	Out = nil;
    	TextFile.WriteFromString(PlayListFolder.."\\"..PlayList..".m3u", Out, false);
    for i=1,Files do
    	Data = ListBox.GetItemData("Playlist", i);
    	Out = Data.."\r\n";
    	TextFile.WriteFromString(PlayListFolder.."\\"..PlayList..".m3u", Out, true);
    end
    elseif proceed == IDNO then
    	PlayList = nil;
    -- ask if save with another name or no
    	note = Dialog.Message("Notice", "Do you want to proceed with another file name?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
    if note == IDYES then
    -- say if the file already exists
    	PlayList = Dialog.Input("File exists", "Please choose another file name :", nil, MB_ICONQUESTION);
    for i=1,Files do
    	Data = ListBox.GetItemData("Playlist", i);
    	Out = Data.."\r\n";
    	TextFile.WriteFromString(PlayListFolder.."\\"..PlayList..".m3u", Out, true);
    end
    elseif note == IDNO then
    end
    end
    else
    for i=1,Files do
    	Data = ListBox.GetItemData("Playlist", i);
    	Out = Data.."\r\n";
    	TextFile.WriteFromString(PlayListFolder.."\\"..PlayList..".m3u", Out, true);
    end
    end
    end
    elseif type == 6 then
    -- do what's needed
    	FolderFound = Folder.DoesExist(PlayListFolder);
    	PlayList = nil;
    	Files = ListBox.GetCount("Playlist");
    if Files == 0 then
    -- say if the playlist is empty
    	Dialog.Message("Notice", "The playlist is empty.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    else
    -- ask for the file name
    	PlayList = Dialog.Input("Please enter the file name.", "File Name:", nil, MB_ICONQUESTION);
    	PlayListFound = File.DoesExist(PlayListFolder.."\\"..PlayList..".xml");
    if PlayListFound == true then
    -- say if the playlist can be overwritten
    	proceed = Dialog.Message("Notice", "The playlist is not empty. Do you want to overwrite?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
    if proceed == IDYES then
    -- do what's needed
    for i=1,Files do
    	File.Copy("AutoPlay\\Docs\\playlist.xml", PlayListFolder.."\\"..PlayList..".xml", false, true, true, true, nil);
    	XML.Load(PlayListFolder.."\\"..PlayList..".xml");
    	Data = ListBox.GetItemData("Playlist", i);
    	XML.InsertXML("*/note", "<file"..i..">"..Data.."</file"..i..">\r\n\r\n", XML.INSERT_AFTER);
    	XML.Save(PlayListFolder.."\\"..PlayList..".xml");
    end
    elseif proceed == IDNO then
    	PlayList = nil;
    -- ask if save with another name or no
    	note = Dialog.Message("Notice", "Do you want to proceed with another file name?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
    if note == IDYES then
    
    -- ask for another file name
    	PlayList = Dialog.Input("File exists", "Please choose another file name :", nil, MB_ICONQUESTION);
    -- do what's needed
    for i=1,Files do
    	File.Copy("AutoPlay\\Docs\\playlist.xml", PlayListFolder.."\\"..PlayList..".xml", false, true, true, true, nil);
    	XML.Load(PlayListFolder.."\\"..PlayList..".xml");
    	Data = ListBox.GetItemData("Playlist", i);
    	XML.InsertXML("*/note", "<file"..i..">"..Data.."</file"..i..">\r\n\r\n", XML.INSERT_AFTER);
    	XML.Save(PlayListFolder.."\\"..PlayList..".xml");
    end
    end
    end
    else
    -- do what's needed
    for i=1,Files do
    	File.Copy("AutoPlay\\Docs\\playlist.xml", PlayListFolder.."\\"..PlayList..".xml", false, true, true, true, nil);
    	XML.Load(PlayListFolder.."\\"..PlayList..".xml");
    	Data = ListBox.GetItemData("Playlist", i);
    	XML.InsertXML("*/note", "<file"..i..">"..Data.."</file"..i..">\r\n\r\n", XML.INSERT_AFTER);
    	XML.Save(PlayListFolder.."\\"..PlayList..".xml");
    end
    end
    end
    end
    end
    end
    Yes, I know, the code is a mess.

Similar Threads

  1. XML format
    By TJ_Tigger in forum AutoPlay Media Studio 5.0
    Replies: 6
    Last Post: 10-04-2005, 12:47 PM
  2. Example: Multiple Choice XML Quiz
    By Brett in forum AutoPlay Media Studio 7.5 Examples
    Replies: 0
    Last Post: 09-15-2005, 10:55 AM
  3. XML plugin Project example - XML Weather from weather.com
    By kpsmith in forum AutoPlay Media Studio 5.0
    Replies: 8
    Last Post: 06-03-2004, 05:25 PM
  4. Spotlight: XML Actions Plugin
    By Desmond in forum AutoPlay Media Studio 5.0
    Replies: 1
    Last Post: 03-15-2004, 03:56 PM
  5. Using XML Or INI files during install
    By djpyne in forum Setup Factory 6.0
    Replies: 0
    Last Post: 10-15-2003, 10:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts