The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: xmlparser | November 22, 2008 @ 10:24am
C Code
[
Download
]
#define NUMBEROFTOKENSALLOWED 5 //working function unsigned char* ReadXML(LPCSTR FileName ) { DWORD BytesRead = 0; DWORD Signature = 0; HANDLE hFile; unsigned char* buffer; hFile = CreateFile( FileName ,GENERIC_WRITE | GENERIC_READ,0, NULL, OPEN_EXISTING,0, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { MessageBox( NULL, "[1]CreateFile", "Error", MB_OK ); return 0; } Map_Data.FileSize = GetFileSize(hFile, NULL); if ( Map_Data.FileSize <= 0 ) { MessageBox( NULL, "GetFileSize", "Error", MB_OK ); CloseHandle( hFile ); return 0; } buffer = new unsigned char[Map_Data.FileSize]; if ( ReadFile( hFile, buffer, Map_Data.FileSize, &BytesRead, NULL ) == 0 ) { MessageBox( NULL, "ReadFile", "Error", MB_OK ); delete[] buffer; CloseHandle( hFile ); return 0; } return buffer; } void parseXML( char* tokens[NUMBEROFTOKENSALLOWED] ) { int needle = 0; DWORD base = 0; if ( strcmp(tokens[0], "<case1>")==0) { if ( strcmp(tokens[1], "<subcase1>")==0) { } if ( strcmp(tokens[1], "<subcase2>")==0) { } } else if ( strcmp(tokens[0], "<case2>")==0) { if ( strcmp(tokens[1], "<subcase1>")==0) { } if ( strcmp(tokens[1], "<subcase2>")==0) { } } else if ( strcmp(tokens[0], "<case2>")==0) { if ( strcmp(tokens[1], "<subcase1>")==0) { } if ( strcmp(tokens[1], "<subcase2>")==0) { } } else if ( strcmp(tokens[0], "<case2>")==0) { if ( strcmp(tokens[1], "<subcase1>")==0) { } if ( strcmp(tokens[1], "<subcase2>")==0) { } } } //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: // tokens[0] = "the" // tokens[1] = "quick" // tokens[2] = "brown" // tokens[3] = "fox" // tokens[4] = "jumps" // tokens[5] = "over" //and the rest is truncated void tokenizerXML( unsigned char* buffer ) { int needle = 0,_needle = 0; DWORD base = 0; char* tokens[NUMBEROFTOKENSALLOWED]; //allow for 6 tokens char* pointer = (char*)buffer; for ( needle = 0; needle <= strlen(buffer); needle++ ) if ( pointer[needle] = 0x32) //SPACE { memcpy(tokens[_needle], (void*)base, needle-base); base = needle; needle++; } parseXML( tokens ); } int main(int argc, char* argv[]) { parseXML( ReadXML("C:\\map.xml") ); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.51 / 8
131 Votes
http://codebin.yi.org/195
page generated in 0.00 seconds