Old 3rd August 2010, 07:31   #1
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
Reading from XML?

Hey everybody!
I'm looking to get som information from an xml-file into Winamp. More specifically get a few integers from an xml-file and then fill an array with these. Is this possible? If so, could anyone point me in the right direction?
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 07:37   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
it would all depend on the xml library that you intend to use, there is an example of how to use the expat based xml library Winamp uses and provides access to in the sdk. otherwise i'd expect other xml libraries show how to get data from an xml file with them.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 09:09   #3
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
Thanks! Are there any alternatives? It doesn't need to be XML I just need a way to read from an external file, could be a txt or anything.
ml_xmlex was way over my head unfortunately..
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 09:13   #4
DrO
 
Join Date: Sep 2003
Posts: 27,873
expat is the only xml library i'm aware off but i'm sure there are others. all you need is just how to use either the runtime file apis or the Win32 file apis and you can process any data from a file if you want to go with a non-xml style format. or if you're only using a small data set then an ini file may be the simplest method without having to create your own file format.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 09:28   #5
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
I will only be working with about 20 integers so maybe .INI would be the way to go?
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 09:48   #6
DrO
 
Join Date: Sep 2003
Posts: 27,873
an ini should be ok for that number of items especially if it's not a frequent reading of the values (ini files are simple to deal with and use but they have the downside of not working well with large or often data access of large numbers of entries).

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 09:53   #7
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
The file should only be read once so that should be fine. Is there an example of dealing with ini somewhere? Thanks yet again!
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 09:57   #8
DrO
 
Join Date: Sep 2003
Posts: 27,873
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx is the best point to start from as its the api you'll need to use (assuming its just plain integers otherwise you'd need to use http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx and convert to the required type from the string).

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 10:15   #9
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
Do I need to know what value to retrieve? "The name of the key whose value is to be retrieved."
Because the way I inteded Winamp doesn't know what values it needs. It's supposed to get whatever values are in the external file?
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 11:09   #10
DrO
 
Join Date: Sep 2003
Posts: 27,873
its easier if you know what the key names will be but you can enum the ini file to get the names of the keys (have to leave the keyname value clear if i remember correctly) and so can then get the values after caching the list of keynames. however with what you've now mentioned, it may just be easier to save the data to a file and read it in manually - is your call really as you've got to work with it and maintain it all in the end.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 11:20   #11
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
What I need is to have a file with a series of ints: 60, 350, 500 and so on. Then I need to load these integers into an array for use in my plugin.
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 11:38   #12
DrO
 
Join Date: Sep 2003
Posts: 27,873
http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx has an example similar to what you're needing i think.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 13:02   #13
Daniyal.A
Junior Member
 
Join Date: Jul 2010
Posts: 11
Hi, Stuving.
Can you explain: 1. What these integers are for? 2. Are these integers supposed to be modified from outside by users?
Daniyal.A is offline   Reply With Quote
Old 3rd August 2010, 13:15   #14
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
Quote:
Originally Posted by Daniyal.A View Post
Hi, Stuving.
Can you explain: 1. What these integers are for? 2. Are these integers supposed to be modified from outside by users?
The integers are positions in a track in seconds. The track will be paused at these tracktimes They are not modified in Winamp, the user can edit the integers in the text/xml/ini-file.
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 13:24   #15
DrO
 
Join Date: Sep 2003
Posts: 27,873
really the best piece of advise is determine how easy you require the files to the editable and go with a storage method which makes that the easiest to go for be it ini, xml, custom text file with values comma or \n separated. once that is decided on then it'll be easier to work out what api/functions to use to achieve it.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 13:32   #16
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
It needs to be fairly easy to edit. Something like you mentioned with the integers separated with just a space or comma.
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 14:06   #17
Daniyal.A
Junior Member
 
Join Date: Jul 2010
Posts: 11
Alright, if you are planning to write an editor to work with the integers, then I would recommend you to store them in binary format. If you want the users to manually edit the integers, then XML is the best choice.
You can use MSXML3 to deal with XML files, since it is included in Windows XP and higher versions of Windows. See this http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx.
Daniyal.A is offline   Reply With Quote
Old 3rd August 2010, 14:20   #18
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
What I had in mind was just for the user to manually edit a text-file which my plugin then would read in and store in an array. MSXML seems way too advanced for me.
Stuvning is offline   Reply With Quote
Old 3rd August 2010, 14:23   #19
DrO
 
Join Date: Sep 2003
Posts: 27,873
xml really is overkill for what's being asked and if xml is to be used it makes more sense to use the xml reader service Winamp provides to cut down on OS dependencies and all that fun stuff.

fread(..) & fscanf(..) and related functions is far simpler and more appropriate for what now appears to be the aim (which i have to admit feels like something that would be set as a first or second week c programming course lab project).

obviously its down to Stuvning to make the final decision but personally i'd not got the route of doing it as an xml file and just do a flat file separated by white-space between the data which fscanf(..) should cope with for reading back in.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 15:13   #20
Daniyal.A
Junior Member
 
Join Date: Jul 2010
Posts: 11
If the integers are used as global for all tracks in playlist, of course a flat-file is a way. But if each track will have its own integers then it should be structured first. For example:

typedef struct
{
LPCWSTR lpFilename;
int *pSeconds;
} TRACK_TO_PAUSE;

In this case I think XML is irreplaceable.
Daniyal.A is offline   Reply With Quote
Old 3rd August 2010, 15:19   #21
siam6606
Junior Member
 
Join Date: May 2010
Posts: 42
Exemple :

// configuration section in winamp.ini
#define CONFIG_SECTION "ml_upnp"

char * conf_file=(char*)SendMessage(plugin.hwndWinampParent,WM_WA_IPC,0,IPC_GETINIFILE);

//READ
int sortdir=GetPrivateProfileInt(CONFIG_SECTION,"direction",0,conf_file);
int sortcol=GetPrivateProfileInt(CONFIG_SECTION,"colonne",sortcol,conf_file);

//WRITE
char str[32];
sprintf(str,"%d",sortdir);
WritePrivateProfileString(CONFIG_SECTION,"direction",str,conf_file);
sprintf(str,"%d",sortcol);
WritePrivateProfileString(CONFIG_SEC,"colonne",str,conf_file);
siam6606 is offline   Reply With Quote
Old 3rd August 2010, 15:22   #22
DrO
 
Join Date: Sep 2003
Posts: 27,873
@Daniyal.A: it sounds more like it will be done as a single file per track so the flat file approach still works. if multiple are wanted then maybe xml is appropriate but it would probably still be valid to go with a custom structure just based around the data involved in the layout you've posted but i don't think xml is an appropriate solution for this situation especially when it's likely most of the data in an xml based file would just be all of the xml structure which seems a waste of space and resources.

-daz
DrO is offline   Reply With Quote
Old 3rd August 2010, 15:26   #23
Stuvning
Junior Member
 
Join Date: May 2010
Posts: 37
I'll be looking into fread and fscanf tomorrow to see if I can implement it. Thanks for the help this far.
Stuvning is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Tags
xml

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump