ISXDK:Using XML Setting Files

From Lavish Software Wiki
Jump to: navigation, search


This tutorial is to teach you how to use XML Setting Files in your custom extensions. I created a simple extension named ISXXML with mkisx to modify xml settings and walk you through what I did. NOTE: The code created in this tutorial is available at

Step 1: Creating an XML file to use

I created a very simple XML file, based loosely on a football players information. The outer set has to be named <InnerSpaceSettings> to work correctly. Inside <InnerSpaceSettings> I create a subset for each player, but you could just as easily make a subset for each team, and have each player be a subset of the team or as many subsets as you would like. Inside each set (player) I have 3 settings, number, position, and years played.

Example code
<?xml version='1.0'?>
         <Set Name="Ralph Wiggum">
		<Setting Name="Number">33</Setting>
		<Setting Name="Position">Wide Receiver</Setting>
		<Setting Name="Years played">1</Setting>

Step 2: Adding new functions to Initialize and Shutdown

I add new functions to load and save my XML file when the extensions loads and shuts down.

Additions to Initialize
Addition to Shutdown

Step 2.1: I add XMLStartup and XMLShutdown to class ISXXML

Here I simply add XMLStartup and XMLShutdown to the other functions called on initialize and shutdown in class ISXXML

Class ISXXML code
class ISXXML :
	public ISXInterface
	virtual bool Initialize(ISInterface *p_ISInterface);
	virtual void Shutdown();

	void ConnectServices();
	void RegisterCommands();
	void RegisterAliases();
	void RegisterDataTypes();
	void RegisterTopLevelObjects();
	void RegisterServices();
	void RegisterTriggers();
        void XMLStartup();
	void DisconnectServices();
	void UnRegisterCommands();
	void UnRegisterAliases();
	void UnRegisterDataTypes();
	void UnRegisterTopLevelObjects();
	void UnRegisterServices();
        void XMLShutdown();
	void DoNothing();

Step 2.2: I create my functions XMLStartup and XMLShutdown

Here are the functions I created to handle opening and saving my XML file.

XMLStartup function.
void ISXXML::XMLStartup()
XMLShutdown function - saves the xml file and outputs success or failure to the console.
void ISXXML::XMLShutdown()
	if (pISInterface->ExportSet(ident,"football.xml"))

Step 3: Adding 3 new commands

Step 3.1: I forward declare my 3 commands

I decide to name my 3 commands ListPlayers, AddPlayer, and RemovePlayer. I also add an unsigned long ident to use a placeholder for my XML's outer set GUID.

int __cdecl CMD_ListPlayers(int argc, char *argv[]);
int __cdecl CMD_AddPlayer(int argc, char *argv[]);
int __cdecl CMD_RemovePlayer(int argc, char *argv[]);
unsigned long ident;

Step 3.2: I add my 3 commands to the RegisterCommands function

RegisterCommands code
void ISXXML::RegisterCommands()

Step 3.3: I add my 3 commands to the UnRegisterCommands function

void ISXXML::UnRegisterCommands()

Step 3.4: I create CMD_ListPlayers and the Listplayers callback function

This section shows CMD_Listplayers which simply uses the pISInterface->EnumSets function to go through each subset of ident (my outer set GUID) and use the callback function ListPlayers on each set. The ListPlayers callback function takes all the data out of each subset and displays it the user.

ListPlayers callback function
void __cdecl ListPlayers(const char *Name, void *pData)
	unsigned long Number=0,YPlayed=0;
	unsigned long ID=pISInterface->FindSet(ident,(char *)Name);
	char Position[50]="\0";
	pISInterface->GetSetting(ID,"Years Played",YPlayed);
	printf("Player Name: %s Number: %d Position: %s Years Played: %d",Name,Number,Position,YPlayed);
int __cdecl CMD_ListPlayers(int argc, char *argv[])
	return 0;

Step 3.5: I create CMD_AddPlayer function

Here I create CMD_AddPlayer. The first part of the function checks to see if the command was given with the incorrect number of arguments and if so it gives the correct syntax and returns from the function. The next part attempts to create a subset of our outer set with the <Name> of the player, if successful it fills in information for number, position, and years played telling the user it was successful. If it fails it it tells the user that the player already exists.

int __cdecl CMD_AddPlayer(int argc, char *argv[])
    if (argc != 5)
	     printf("Syntax: %s <Name> <Number> <Position> <Years Played>",argv[0]);
	     return 0;
	unsigned long ID=pISInterface->CreateSet(ident,argv[1]);
	if (ID!=0)
	     pISInterface->SetSetting(ID,"Years Played",argv[4]);
	     printf("Player %s added!",argv[1]);
	     printf("Player already exists");
return 0;

Step 3.6: I create CMD_RemovePlayer function

Here I create CMD_RemovePlayer function. If it is not given exactly two arguments (name of the command is argv[0], <name> is argv[1] totalling two arguments) it will display the syntax and return out of the function, otherwise it finds the set with the given <name> and clears it. It will return <name> deleted! on success and <name> not found on failure.

int __cdecl CMD_RemovePlayer(int argc, char *argv[])
	if (argc != 2)
               printf("Syntax: %s <Name>",argv[0]);
 		return 0;
		unsigned long ID=pISInterface->FindSet(ident,argv[1]);
		if (pISInterface->ClearSet(ID))
			printf("%s deleted!",argv[1]);
			printf("%s not found",argv[1]);
	return 0;

See Also