In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Difference between revisions of "Talk:Mini-XML"

From WiiBrew
Jump to navigation Jump to search
m
Line 1: Line 1:
 
 
== Loading from an XML With default values to fall back on ==
 
== Loading from an XML With default values to fall back on ==
  
I found the following code usefull, please not using this demands you check for NULL yourself!
+
I found the following code usefull, please note using this demands you check for NULL yourself!
 
This should not pose a problem, as Name is most likely a constant string.
 
This should not pose a problem, as Name is most likely a constant string.
  

Revision as of 11:24, 20 August 2009

Loading from an XML With default values to fall back on

I found the following code usefull, please note using this demands you check for NULL yourself! This should not pose a problem, as Name is most likely a constant string.

Loading settings from a XML with these is easier, as you don't have to check and correct manually in the loading code.

#include <mxml.h>

//watch out for unsafe code!
//USE WITH CAUTION!!!
int mxml_GetInt(mxml_node_s * node, const char * name, int default_value)
{
	const char * value = mxmlElementGetAttr(node,name);
	if(value)
	{
		return atoi(value);
	}
	return default_value;
}

//watch out for unsafe code!
//USE WITH CAUTION!!!
// use strcpy if you want to keep the string (the result is a char[] that is replaced or freed)
const char * mxml_GetString(mxml_node_s * node, const char * name, char * default_value)
{
	const char * value = mxmlElementGetAttr(node,name);
	if(value)
	{
		return value;
	}
	return default_value;
}

Freezy 09:23, 20 August 2009 (UTC)