Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

parseXmlString.cc

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: parseXmlString.cc,v 1.7 2004/01/15 00:02:25 fisyak Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: parses Xml file & returns contents between request TAGs 00009 * 00010 *************************************************************************** 00011 * 00012 * $Log: parseXmlString.cc,v $ 00013 * Revision 1.7 2004/01/15 00:02:25 fisyak 00014 * Replace ostringstream => StString, add option for alpha 00015 * 00016 * Revision 1.6 2003/09/16 22:44:18 porter 00017 * got rid of all ostrstream objects; replaced with StString+string. 00018 * modified rules.make and added file stdb_streams.h for standalone compilation 00019 * 00020 * Revision 1.5 2003/09/02 17:57:50 perev 00021 * gcc 3.2 updates + WarnOff 00022 * 00023 * Revision 1.4 2000/01/10 20:37:55 porter 00024 * expanded functionality based on planned additions or feedback from Online work. 00025 * update includes: 00026 * 1. basis for real transaction model with roll-back 00027 * 2. limited SQL access via the manager for run-log & tagDb 00028 * 3. balance obtained between enumerated & string access to databases 00029 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00030 * 5. restructured Node model for better XML support 00031 * 00032 * Revision 1.3 1999/12/28 21:31:42 porter 00033 * added 'using std::vector' and 'using std::list' for Solaris CC5 compilation. 00034 * Also fixed some warnings arising from the CC5 compiles 00035 * 00036 * Revision 1.2 1999/09/30 02:06:15 porter 00037 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00038 * allow multiple rows (StDbTable), & Added the comment sections at top of 00039 * each header and src file 00040 * 00041 **************************************************************************/ 00042 #include "parseXmlString.hh" 00043 #include "stdb_streams.h" 00044 #include <string.h> 00045 00047 00048 char* 00049 parseXmlString::getString(char* line, char* key1, char* key2){ 00050 00051 00052 char* p1 = 0; 00053 char* p = &line[0]; 00054 00055 int i1 = getIndexAfter(line, key1); 00056 if(!i1) return p1; 00057 int i2 = getIndexBefore(line, key2); 00058 if(!i2) return p1; 00059 00060 00061 int size = i2-i1+1; 00062 if(i2<i1){ 00063 cerr << " Missing Key " << endl; 00064 return p1; 00065 } 00066 00067 for (int i=0; i<i1-1; i++)p++; 00068 00069 p1 = new char[size+1]; 00070 strncpy(p1,p,size); 00071 p1[size]='\0'; 00072 00073 // cout << p1 << endl; 00074 char* retVal = removeBlankEnds(p1); 00075 delete [] p1; 00076 return retVal; 00077 // return removeBlankEnds(p1); 00078 } 00079 00081 00082 char* 00083 parseXmlString::getStringAfter(char* line, char* key){ 00084 00085 int i = getIndexAfter(line,key); 00086 char* tmp =0; 00087 00088 if(!i)return tmp; 00089 00090 char* p1 = &line[i]; 00091 00092 int k = strlen(line); 00093 int size = k-i; 00094 00095 tmp = new char[size+1]; 00096 strncpy(tmp,p1,size); 00097 00098 tmp[size] = '\0'; 00099 char* retVal = removeBlankEnds(tmp); 00100 delete [] tmp; 00101 return retVal; 00102 // return removeBlankEnds(tmp); 00103 00104 } 00105 00107 00108 char* 00109 parseXmlString::getStringBefore(char* line, char* key){ 00110 00111 int i = getIndexBefore(line,key); 00112 00113 char * tmp = 0; 00114 if(!i)return tmp; 00115 char* p1 = &line[0]; 00116 int size = i; 00117 tmp = new char[size+1]; 00118 strncpy(tmp,p1,size); 00119 tmp[size] = '\0'; 00120 00121 char* retVal = removeBlankEnds(tmp); 00122 delete [] tmp; 00123 return retVal; 00124 // return removeBlankEnds(tmp); 00125 } 00126 00128 00129 int 00130 parseXmlString::getIndexAfter(char* line, char* key){ 00131 00132 if(!line || !key)return 0; 00133 char* id = strstr(line,key); 00134 if(!id)return 0; //use as bool 00135 00136 int i = id - line; 00137 i += strlen(key)+1; 00138 return i; 00139 } 00140 00142 00143 int 00144 parseXmlString::getIndexBefore(char* line, char* key){ 00145 00146 if(!line || !key) return 0; 00147 char* id = strstr(line,key); 00148 if(!id) return 0; //use as bool 00149 int i = id - line; 00150 return i--; 00151 00152 } 00153 00155 00156 char* 00157 parseXmlString::removeBlankEnds(char* line){ 00158 00159 char* p1 = &line[0]; 00160 int k = strlen(line); 00161 int i,j; 00162 00163 for(i=0; i<k; i++){ 00164 if(line[i]!=' ')break; 00165 p1++; 00166 } 00167 00168 for(j=k; j>0; j--){ 00169 if(line[j]=='\0')continue; 00170 if(line[j]!=' ')break; 00171 } 00172 00173 int size = j-i+1; 00174 char* tmp = new char[size+1]; 00175 strncpy(tmp,p1,size); 00176 tmp[size] = '\0'; 00177 00178 //delete [] line; 00179 return tmp; 00180 } 00181 00182 00183 00184 00185 00186 00187

Generated on Thu Aug 24 14:45:25 2006 for Doxygen by doxygen 1.3.7