1. #define NUMBEROFTOKENSALLOWED 5
  2.  
  3. //working function
  4. unsigned char* ReadXML(LPCSTR FileName )
  5. {
  6. DWORD BytesRead = 0;
  7. DWORD Signature = 0;
  8. HANDLE hFile;
  9. unsigned char* buffer;
  10.  
  11. hFile = CreateFile( FileName ,GENERIC_WRITE | GENERIC_READ,0, NULL, OPEN_EXISTING,0, NULL);
  12. if ( hFile == INVALID_HANDLE_VALUE )
  13. {
  14. MessageBox( NULL, "[1]CreateFile", "Error", MB_OK );
  15. return 0;
  16. }
  17. Map_Data.FileSize = GetFileSize(hFile, NULL);
  18. if ( Map_Data.FileSize <= 0 )
  19. {
  20. MessageBox( NULL, "GetFileSize", "Error", MB_OK );
  21. CloseHandle( hFile );
  22. return 0;
  23. }
  24. buffer = new unsigned char[Map_Data.FileSize];
  25. if ( ReadFile( hFile, buffer, Map_Data.FileSize, &BytesRead, NULL ) == 0 )
  26. {
  27. MessageBox( NULL, "ReadFile", "Error", MB_OK );
  28. delete[] buffer;
  29. CloseHandle( hFile );
  30. return 0;
  31. }
  32. return buffer;
  33. }
  34.  
  35.  
  36. void parseXML( char* tokens[NUMBEROFTOKENSALLOWED] )
  37. {
  38. int needle = 0;
  39. DWORD base = 0;
  40. if ( strcmp(tokens[0], "<case1>")==0)
  41. {
  42. if ( strcmp(tokens[1], "<subcase1>")==0)
  43. {
  44.  
  45. }
  46. if ( strcmp(tokens[1], "<subcase2>")==0)
  47. {
  48.  
  49. }
  50. }
  51. else if ( strcmp(tokens[0], "<case2>")==0)
  52. {
  53. if ( strcmp(tokens[1], "<subcase1>")==0)
  54. {
  55.  
  56. }
  57. if ( strcmp(tokens[1], "<subcase2>")==0)
  58. {
  59.  
  60. }
  61. }
  62. else if ( strcmp(tokens[0], "<case2>")==0)
  63. {
  64. if ( strcmp(tokens[1], "<subcase1>")==0)
  65. {
  66.  
  67. }
  68. if ( strcmp(tokens[1], "<subcase2>")==0)
  69. {
  70.  
  71. }
  72. }
  73. else if ( strcmp(tokens[0], "<case2>")==0)
  74. {
  75. if ( strcmp(tokens[1], "<subcase1>")==0)
  76. {
  77.  
  78. }
  79. if ( strcmp(tokens[1], "<subcase2>")==0)
  80. {
  81.  
  82. }
  83. }
  84. }
  85.  
  86.  
  87. //the idea here is to create "tokens" or keywords. so we're going to seperate every word in the sentance and put it in an array tokens. and pass it over to //parseXML. so a string of "the quick brown fox jumped over the lazy dog" would become:
  88. // tokens[0] = "the"
  89. // tokens[1] = "quick"
  90. // tokens[2] = "brown"
  91. // tokens[3] = "fox"
  92. // tokens[4] = "jumps"
  93. // tokens[5] = "over"
  94. //and the rest is truncated
  95.  
  96.  
  97. void tokenizerXML( unsigned char* buffer )
  98. {
  99. int needle = 0,_needle = 0;
  100. DWORD base = 0;
  101. char* tokens[NUMBEROFTOKENSALLOWED]; //allow for 6 tokens
  102. char* pointer = (char*)buffer;
  103. for ( needle = 0; needle <= strlen(buffer); needle++ )
  104. if ( pointer[needle] = 0x32) //SPACE
  105. {
  106. memcpy(tokens[_needle], (void*)base, needle-base);
  107. base = needle;
  108. needle++;
  109. }
  110.  
  111. parseXML( tokens );
  112. }
  113.  
  114. int main(int argc, char* argv[])
  115. {
  116. parseXML( ReadXML("C:\\map.xml") );
  117. return 0;
  118. }