Talk:Mini-XML
Jump to navigation
Jump to search
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 (and node was most likely already checked).
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)
Problem with devkitPro r18
With the devkitPro r18, I get the errors:
1>linking ... boot.elf 1>c:/devkitPro/libogc/lib/wii\libmxml.a(mxml-file.o): In function `mxml_get_entity': 1>/home/ew562c/Dev/wiichat/Client/mxml-2.5/mxml-file.c(1423): undefined reference to `__ctype_ptr' 1>/home/ew562c/Dev/wiichat/Client/mxml-2.5/mxml-file.c(1423): undefined reference to `__ctype_ptr' 1>c:/devkitPro/libogc/lib/wii\libmxml.a(mxml-string.o): In function `_mxml_vsnprintf': 1>/home/ew562c/Dev/wiichat/Client/mxml-2.5/mxml-string.c(209): undefined reference to `__ctype_ptr' 1>/home/ew562c/Dev/wiichat/Client/mxml-2.5/mxml-string.c(177): undefined reference to `__ctype_ptr' 1>/home/ew562c/Dev/wiichat/Client/mxml-2.5/mxml-string.c(209): undefined reference to `__ctype_ptr' 1>collect2: ld returned 1 exit status
—Preceding unsigned comment added by Freezy (talk • contribs)