00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "FEDM_XmlParser_IReader.h"
00033 #include "FEDM_XmlParser_Base.h"
00034
00035
00036
00037
00038
00039 FEDM_XmlParser_Reader::FEDM_XmlParser_Reader(void)
00040 {
00041 m_pXmlParser = NULL;
00042 }
00043
00044 FEDM_XmlParser_Reader::~FEDM_XmlParser_Reader(void)
00045 {
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int FEDM_XmlParser_Reader::SerializeHeaderIn(FEDM_XML_TREEITEM* root, const char* szVendor)
00065 {
00066 if(root == NULL)
00067 {
00068 m_pXmlParser->SetLastError(FEDM_ERROR_NULL_POINTER);
00069 return FEDM_ERROR_NULL_POINTER;
00070 }
00071
00072 char cValue[512];
00073 wchar_t wcTmp[FEDM_MAX_TEXT_SIZE+2];
00074 wstring sTmp;
00075 unsigned int uiValue[3];
00076 FEDM_XML_TREEITEM* child = NULL;
00077 FEDM_XML_TREEITEM* parent = NULL;
00078
00079
00080
00081
00082 child = FindTag(FEDM_XML_TAG_FILE_HDR_UC, (unsigned int)1);
00083 if(child == NULL)
00084 {
00085 DeleteXmlTree();
00086 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00087 return m_pXmlParser->GetLastError();
00088 }
00089 AddTagItem(root, child);
00090 parent = child;
00091
00092
00093 child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC, (unsigned int)2);
00094 if(child == NULL)
00095 {
00096 DeleteXmlTree();
00097 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00098 return m_pXmlParser->GetLastError();
00099 }
00100 if(child->sValue.length() < FEDM_MAX_TEXT_SIZE)
00101 {
00102 for (unsigned int i = 0; i < child->sValue.length(); i++)
00103 m_pXmlParser->m_XmlHeader.szDocType[i] = (char)(child->sValue.c_str())[i];
00104 }
00105 AddTagItem(parent, child);
00106
00107
00108 child = FindTag(FEDM_XML_TAG_DOC_VERSION_UC, (unsigned int)2, true);
00109 if(child == NULL)
00110 {
00111 DeleteXmlTree();
00112 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00113 return m_pXmlParser->GetLastError();
00114 }
00115 memset(uiValue, 0, 3);
00116 #if defined(_MSC_VER)
00117 swscanf(child->sValue.c_str(), L"%S", cValue);
00118 #else
00119 swscanf(child->sValue.c_str(), L"%s", cValue);
00120 #endif
00121 sscanf(cValue, "%u.%u", &uiValue[0], &uiValue[1]);
00122 m_pXmlParser->m_XmlHeader.uiDocVersion = (((unsigned char)uiValue[0]) << 8) + (unsigned char)uiValue[1];
00123 AddTagItem(parent, child);
00124
00125
00126 child = FindTag(FEDM_XML_TAG_VENDOR_UC, (unsigned int)2, true);
00127 if(child == NULL)
00128 {
00129 DeleteXmlTree();
00130 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00131 return m_pXmlParser->GetLastError();
00132 }
00133 if(strlen(szVendor) > 0)
00134 {
00135 #if defined(__BORLANDC__) || defined(_MSC_VER)
00136 #if _MSC_VER <= 1200
00137 swprintf(wcTmp, L"%S", szVendor);
00138 #else
00139 #if defined(_WIN32_WCE)
00140 swprintf(wcTmp, L"%S", szVendor);
00141 #else
00142 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"%S", szVendor);
00143 #endif
00144 #endif
00145 #else
00146 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"%s", szVendor);
00147 #endif
00148 }
00149 else
00150 {
00151 #if defined(__BORLANDC__) || defined(_MSC_VER)
00152 #if _MSC_VER <= 1200
00153 swprintf(wcTmp, L"FEIG ELECTRONIC");
00154 #else
00155 #if defined(_WIN32_WCE)
00156 swprintf(wcTmp, L"FEIG ELECTRONIC");
00157 #else
00158 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"FEIG ELECTRONIC");
00159 #endif
00160 #endif
00161 #else
00162 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"FEIG ELECTRONIC");
00163 #endif
00164 }
00165 sTmp = wcTmp;
00166 if(child->sValue != wcTmp)
00167 {
00168 delete child;
00169 DeleteXmlTree();
00170 m_pXmlParser->SetLastError(FEDM_XML_ERROR_DOC_FILE_TYPE);
00171 return m_pXmlParser->GetLastError();
00172 }
00173 if(strlen(szVendor) > 0)
00174 strcpy(m_pXmlParser->m_XmlHeader.szVendor, szVendor);
00175 else
00176 strcpy(m_pXmlParser->m_XmlHeader.szVendor, "FEIG ELECTRONIC");
00177 AddTagItem(parent, child);
00178
00179
00180 child = FindTag(FEDM_XML_TAG_FEDM_VERSION_UC, (unsigned int)2, true);
00181 if(child == NULL)
00182 {
00183 DeleteXmlTree();
00184 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00185 return m_pXmlParser->GetLastError();
00186 }
00187 memset(uiValue, 0, 3);
00188 #if defined(_MSC_VER)
00189 swscanf(child->sValue.c_str(), L"%S", cValue);
00190 #else
00191 swscanf(child->sValue.c_str(), L"%s", cValue);
00192 #endif
00193 sscanf(cValue, "%02u.%02u.%02u", &uiValue[0], &uiValue[1], &uiValue[2]);
00194 m_pXmlParser->m_XmlHeader.uiFedmVersion = (((unsigned char)uiValue[0]) << 16) + (((unsigned char)uiValue[1]) << 8) + (unsigned char)uiValue[2];
00195 AddTagItem(parent, child);
00196
00197
00198 child = FindTag(FEDM_XML_TAG_COMMENT_UC, (unsigned int)2, true);
00199 if(child == NULL)
00200 {
00201 DeleteXmlTree();
00202 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00203 return m_pXmlParser->GetLastError();
00204 }
00205 if(child->sValue.length() < FEDM_MAX_TEXT_SIZE)
00206 {
00207 for (unsigned int i = 0; i < child->sValue.length(); i++)
00208 m_pXmlParser->m_XmlHeader.szComment[i] = (char)(child->sValue.c_str())[i];
00209 }
00210 AddTagItem(parent, child);
00211
00212
00213 child = FindTag(FEDM_XML_TAG_CRC_UC, (unsigned int)2, true);
00214 if(child == NULL)
00215 {
00216 DeleteXmlTree();
00217 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00218 return m_pXmlParser->GetLastError();
00219 }
00220 #if defined(_MSC_VER)
00221 swscanf(child->sValue.c_str(), L"%S", cValue);
00222 #else
00223 swscanf(child->sValue.c_str(), L"%s", cValue);
00224 #endif
00225 sscanf(cValue, "%u", &m_pXmlParser->m_XmlHeader.uiCrc);
00226 AddTagItem(parent, child);
00227
00228 m_pXmlParser->SetLastError(FEDM_OK);
00229 return m_pXmlParser->GetLastError();
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 int FEDM_XmlParser_Reader::GetTagAttrib( FEDM_XML_TREEITEM* item,
00247 int iIndex,
00248 string& sAttrib,
00249 string& sValue)
00250 {
00251 if(item == NULL)
00252 {
00253 m_pXmlParser->SetLastError(FEDM_ERROR_NULL_POINTER);
00254 return FEDM_ERROR_NULL_POINTER;
00255 }
00256
00257 if((int)item->aAttribList.size() <= iIndex)
00258 {
00259 m_pXmlParser->SetLastError(FEDM_XML_ERROR_NO_TAG_ATTRIBUTE);
00260 return m_pXmlParser->GetLastError();
00261 }
00262
00263 char cBuffer[256];
00264
00265
00266 if(item->aAttribList[iIndex]->sAttribute.size() > 256)
00267 {
00268 m_pXmlParser->SetLastError(FEDM_ERROR_STRING_LENGTH);
00269 return m_pXmlParser->GetLastError();
00270 }
00271
00272
00273 if(item->aAttribList[iIndex]->sValue.size() > 256)
00274 {
00275 m_pXmlParser->SetLastError(FEDM_ERROR_STRING_LENGTH);
00276 return m_pXmlParser->GetLastError();
00277 }
00278
00279 #if defined(__BORLANDC__) || defined(_MSC_VER)
00280 sprintf(cBuffer, "%S", item->aAttribList[iIndex]->sAttribute.c_str());
00281 #else
00282 sprintf(cBuffer, "%S", (const char*)item->aAttribList[iIndex]->sAttribute.c_str());
00283 #endif
00284 sAttrib = cBuffer;
00285
00286 #if defined(__BORLANDC__) || defined(_MSC_VER)
00287 sprintf(cBuffer, "%S", item->aAttribList[iIndex]->sValue.c_str());
00288 #else
00289 sprintf(cBuffer, "%S", (const char*)item->aAttribList[iIndex]->sValue.c_str());
00290 #endif
00291 sValue = cBuffer;
00292
00293 m_pXmlParser->SetLastError(FEDM_OK);
00294 return m_pXmlParser->GetLastError();
00295 }
00296