Advertisement
Shiny_

XML 0.2

Jul 27th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.22 KB | None | 0 0
  1. #include <a_samp>
  2. #if !defined isnull
  3.     #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  4. #endif
  5.  
  6. #define XML. XML_
  7. new str[256];
  8.  
  9. stock XML_Write(File: file, filename[], tag[], tag_msg[], Float: version = 1.0, encoding[] = "us-ascii")
  10. {
  11.     file = fopen(filename, io_write);
  12.     if(!version) return false;
  13.     else if(isnull(encoding)) return false;
  14.     else if(!file) return printf("Błąd podczas tworzenia pliku \"%s\".", filename);
  15.     filename[strfind(filename, ".xml")] = false;
  16.     format(str, sizeof(str), "<?xml version = \"%.1f\" encoding = \"%s\"?>\n\t<%s>\n\t\t<%s>%s</%s>\n\t</%s>", version, encoding, filename, tag, tag_msg, tag, filename);
  17.     return fwrite(file, str), fclose(file);
  18. }
  19.  
  20. stock XML_Read(File: file, filename[], tag[])
  21. {
  22.     file = fopen(filename, io_read);
  23.     if(!file) return printf("Błąd podczas tworzenia pliku \"%s\".", filename);
  24.     new buffer[160];
  25.  
  26.     while(fread(file, buffer))
  27.     {
  28.         if(!strcmp(tag, buffer)) return buffer[strlen(tag)+2]; // +2 = <tag>
  29.     }
  30. }
  31.  
  32. main()
  33. {
  34.     new File: test;
  35.     printf("HELOŁ.\nZAPISUJEMY...");
  36.     XML.Write(test, "testing.xml", "tag", "ęłęłó", 1.0, "UTF-8");
  37.     printf("HELOŁ.\nODCZYTUJEMY...");
  38.     XML.Read(test, "testing.xml", "tag");
  39.     return false;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement