00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #include <fstream>
00025 #include "weHtmlEntity.h"
00026 #include "weTagScanner.h"
00027 
00028 using namespace std;
00029 
00030 const char* html = "<html><body><p align=right dir='rtl'>Begin &    © back</p>"
00031 "<a href=http://terrainformatica.com/index.php?a=1&b=2>link</a><br/><!-- comment -->"
00032 "<script language='jscript'>document.write(\"<h1>test</h1><hr size='1'>\");</script>"
00033 "</body></html>";
00034 
00035 int main(int argc, char* argv[])
00036 {
00037     WeBlob  file;
00038     WeInStream *st;
00039     WeStrStream *si;
00040 
00041     if (argc > 1) {
00042         ifstream ifs(argv[1]);
00043         file.read(ifs);
00044         st = file.stream();
00045     }
00046     else {
00047         si = new WeStrStream(html);
00048         st = si;
00049     }
00050     WeTagScanner sc(*st);
00051 
00052     while(true)
00053     {
00054         int t = sc.GetToken();
00055         switch(t)
00056         {
00057         case wstError:
00058             printf("ERROR\n");
00059             break;
00060         case wstEof:
00061             printf("EOF\n");
00062             goto FINISH;
00063         case wstTagStart:
00064             printf("TAG START:%s\n", sc.GetTagName());
00065             break;
00066         case wstTagEnd:
00067             printf("TAG END:%s\n", sc.GetTagName());
00068             break;
00069         case wstAttr:
00070             printf("\tATTR:%s=%s\n", sc.GetAttrName(), sc.GetValue());
00071             break;
00072         case wstCommentStart:
00073             printf("COMMENT START\n");
00074             break;
00075         case wstCommentEnd:
00076             printf("COMMENT END\n");
00077             break;
00078         case wstData:
00079             printf("\tDATA = %s\n", sc.GetValue());
00080             break;
00081         case wstWord: 
00082         case wstSpace:
00083             printf("{%s}\n", sc.GetValue());
00084             break;
00085         }
00086     }
00087 FINISH:
00088     printf("--------------------------\n");
00089     return 0;
00090 }
00091