Guest User

sXML Test

a guest
Aug 27th, 2012
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.89 KB | None | 0 0
  1. new str[128];
  2. new XMLNode: banksDoc = xmlLoadFile("scriptfiles/mixed.xml"); // Load a xml
  3.  
  4. if (!banksDoc){ // If could not be loaded
  5.     xmlLastErrorDesc( str ); // Get error description
  6.     new lastrow = xmlLastErrorRow(); // Get error row
  7.     new lastcol = xmlLastErrorCol(); // Get error col
  8.     printf("%s  ( Row: %d ) (Col: %d)",str,lastrow,lastcol); // print it
  9.     return 1; // exit function
  10. }
  11.  
  12. // If loaded successfully
  13. /*
  14.     Mixed.xml content:
  15.         <mixed>
  16.             <businness>
  17.                 <property type="1" x="" y="" z="">4Dragon's Casino</property>
  18.             </businness>
  19.             <house>
  20.                 <property type="0" x="" y="" z="">Dynamic House</property>
  21.             </house>
  22.             <police>
  23.                 <property type="2" x="" y="" z="">LSPD</property>
  24.             </police>
  25.             <banks>
  26.                 <bank type="1" x="" y="" z="">Bank 1</property>
  27.                 <bank type="2" x="" y="" z="">Bank 2</property>
  28.                 <bank type="3" x="" y="" z="">Bank 3</property>
  29.                 <bank type="1" x="" y="" z="">Bank 4</property>
  30.             </bank>
  31.         </mixed>
  32. */
  33.  
  34. // How can we get banksDoc ?
  35. // Easy only while loop.
  36.  
  37. new XMLNode: banksNode = xmlFindChild (banksDoc, "banks");
  38. new XMLNode: propertyNode ;
  39. new i = 0;
  40. while ( (propertyNode = xmlFindChild(banksNode, "bank", i)) ){ // if bank exists in the current idx
  41.     xmlNodeGetAttribute (propertyNode,"type",str); // Copy type attr to str
  42.     new type = strval(str);
  43.     xmlNodeGetAttribute (propertyNode,"x",str); // Copy x pos to str
  44.     new Float:x = floatstr(str);
  45.     xmlNodeGetAttribute (propertyNode,"y",str); // Copy y pos to str
  46.     new Float:y = floatstr(str);
  47.     xmlNodeGetAttribute (propertyNode,"z",str); // Copy z pos to str
  48.     new Float:z = floatstr(str);
  49.     xmlNodeGetValue(propertyNode, str); // Copy tag content (in this case Bank Name) to str
  50.     CreateBank (type,x,y,z,str); // It's not SAMP function...Just example
  51.     i++;
  52. }
  53.  
  54.  
  55. xmlUnloadFile(banksDoc); // Unload it, It's really important to delete it from memory...
  56.  
  57. printf(" %d Bank loaded ", i);
Advertisement
Add Comment
Please, Sign In to add comment