// 이 함수의 리턴 값인 IXMLDOMNode 포인터는 쓰고 난 후에 Release를 해야한다. MSXML2::IXMLDOMNode* XMLPaser::ND_pGetTableNode( LPCTSTR strTable ) { MSXML2::IXMLDOMNode *pWorksheetNode = NULL; MSXML2::IXMLDOMNode *pTableNode = NULL; long lFoundWorksheet = -1; try { m_pNodeList->reset(); for ( long i = 0; i < m_lTableCount; i++ ) { m_pNodeList->get_item( i, &pWorksheetNode ); if ( pWorksheetNode ) { MSXML2::IXMLDOMNamedNodeMap* pNodeMap; if ( SUCCEEDED( pWorksheetNode->get_attributes( &pNodeMap ) ) && pNodeMap ) { MSXML2::IXMLDOMNode *pAttributeNode = NULL; pNodeMap->get_item( 0, &pAttributeNode ); if ( pAttributeNode ) { BSTR bstrName; _variant_t varTableName; pAttributeNode->get_nodeName( &bstrName ); LPSTR pszName; UnicodeToAnsi( bstrName, &pszName ); if ( strcmp( pszName, _T("ss:Name") ) == 0 ) { pAttributeNode->get_nodeValue( &varTableName ); if ( varTableName.vt == VT_BSTR ) { LPSTR pszTableName; UnicodeToAnsi( varTableName.bstrVal, &pszTableName ); // Found Worksheet! if ( stricmp( strTable, pszTableName ) == 0 ) { lFoundWorksheet = i; } CoTaskMemFree( pszTableName ); } } CoTaskMemFree( pszName ); pAttributeNode->Release(); VariantClear( &varTableName ); ::SysFreeString( bstrName ); } pNodeMap->Release(); } pWorksheetNode->Release(); } } if ( lFoundWorksheet < 0 ) throw ( 0 ); m_pNodeList->get_item( lFoundWorksheet, &pWorksheetNode ); if ( pWorksheetNode ) { MSXML2::IXMLDOMNodeList* pNodeList; pWorksheetNode->get_childNodes( &pNodeList ); if ( pNodeList ) { for ( long i = 0; i < pNodeList->Getlength(); i++ ) { pNodeList->get_item( i, &pTableNode ); if ( pTableNode ) { BSTR bstrName; pTableNode->get_nodeName( &bstrName ); LPSTR pszName; UnicodeToAnsi( bstrName, &pszName ); if ( strcmp( pszName, _T("Table") ) == 0 ) { CoTaskMemFree( pszName ); ::SysFreeString( bstrName ); pNodeList->Release(); pWorksheetNode->Release(); return ( pTableNode ); } CoTaskMemFree( pszName ); ::SysFreeString( bstrName ); } } pNodeList->Release(); } pWorksheetNode->Release(); } return ( NULL ); } catch(...) { return ( NULL ); } }
HRESULT XMLPaser::ND_hrGetTableValue( LPCTSTR strTable, LPCTSTR strField, UINT idxRow, TCHAR* pVal ) { HRESULT hr = E_FAIL; MSXML2::IXMLDOMNode *pNode = NULL; long idxColumn = -1; long lTableChilds = 0; long lfirstRow = 0; try { pNode = ND_pGetTableNode( strTable ); if ( pNode ) { MSXML2::IXMLDOMNodeList* pRowNodeList; pNode->get_childNodes( &pRowNodeList ); if ( pRowNodeList ) { pRowNodeList->get_length( &lTableChilds ); MSXML2::IXMLDOMNode *pRowNode; BSTR bstrName; LPSTR pszName; for ( long ll = 0; ll < lTableChilds; ll++ ) { pRowNodeList->get_item( ll, &pRowNode ); pRowNode->get_baseName( &bstrName ); // 처음 Row가 나오는 순간 UnicodeToAnsi( bstrName, &pszName ); if ( stricmp( pszName, _T("Row") ) == 0 ) { lfirstRow = ll; CoTaskMemFree( pszName ); ::SysFreeString( bstrName ); break; } CoTaskMemFree( pszName ); ::SysFreeString( bstrName ); } if ( lfirstRow >= lTableChilds ) { return ( E_FAIL ); } pRowNodeList->get_item( lfirstRow, &pRowNode ); if ( pRowNode ) { MSXML2::IXMLDOMNodeList* pCellNodeList; pRowNode->get_childNodes( &pCellNodeList ); if ( pCellNodeList ) { long lCell = 0; pCellNodeList->get_length( &lCell ); for ( long ll = 0; ll < lCell; ll++ ) { MSXML2::IXMLDOMNode *pCellNode; pCellNodeList->get_item( ll, &pCellNode ); if ( pCellNode ) { MSXML2::IXMLDOMNode *pDataNode; pCellNode->get_firstChild( &pDataNode ); if ( pDataNode ) { LPSTR pszColumnName; pDataNode->get_text( &bstrName ); UnicodeToAnsi( bstrName, &pszColumnName ); if ( stricmp( pszColumnName, strField ) == 0 ) { idxColumn = ll; } CoTaskMemFree( pszColumnName ); ::SysFreeString( bstrName ); pDataNode->Release(); } pCellNode->Release(); } } pCellNodeList->Release(); } pRowNode->Release(); } pRowNodeList->get_item( idxRow + lfirstRow + 1, &pRowNode ); if ( pRowNode ) { MSXML2::IXMLDOMNodeList* pCellNodeList; pRowNode->get_childNodes( &pCellNodeList ); if ( pCellNodeList ) { MSXML2::IXMLDOMNode *pDataNode; pCellNodeList->get_item( idxColumn, &pDataNode ); if ( pDataNode ) { BSTR bstrData; LPSTR pszData; pDataNode->get_text( &bstrData ); UnicodeToAnsi( bstrData, &pszData ); strcpy( pVal, pszData ); hr = S_OK; CoTaskMemFree( pszData ); ::SysFreeString( bstrData ); pDataNode->Release(); } pCellNodeList->Release(); } pRowNode->Release(); } pRowNodeList->Release(); } pNode->Release(); } return ( hr ); } catch(...) { return ( E_FAIL ); } }
//通过WebService查询在巡防的终端信息,当终端发来GPS数据时,用来判断该终端是否在巡防, //如果是还要将该GPS数据发给巡防管理服务 BOOL CDBManage_WebServer::WebServer_LoadDB_PatrolDeviceInfo(BOOL isUpdateOnLineDeviceList) { BOOL bRet = FALSE; if (!gPGisMainCtrlProc.m_BusinessManage_ConnectToGPSCheckServer.m_PatrolDevListData.IsEmpty()) { gPGisMainCtrlProc.m_BusinessManage_ConnectToGPSCheckServer.m_PatrolDevListData.ClearAll(); } if(m_bWebServiceConn) { MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr; hr=pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument)); if(FAILED(hr)) { gWriteLogApp.WriteLog( FOR_ALARM,_T("%s [SYS] 无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库\n"),CTime::GetCurrentTime().Format("%H:%M:%S")); return FALSE; } CComBSTR hiResult; m_pWebService->HYTPGIS_PatroAreaUser_QueryAllDevice(&hiResult); char *pStr = NULL; pStr = _com_util::ConvertBSTRToString(hiResult); CString strXML; strXML.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?><DataSet xmlns=\"http://tempuri.org/\"> %s</DataSet>",pStr); VARIANT_BOOL bRet = pDoc->loadXML((_bstr_t)strXML); if(bRet == -1) { MSXML2::IXMLDOMNodeListPtr pListNode; pListNode = pDoc->selectNodes("//Table"); if(pListNode != NULL) { int i; long tLen; pListNode->get_length(&tLen); CString strTemp; for(i = 0 ; i < tLen; i++) { int j = 0; MSXML2::IXMLDOMNode *pTempNode; pListNode->get_item(i,&pTempNode); MSXML2::IXMLDOMNodeList *TempChildList; pTempNode->get_childNodes(&TempChildList); long listCount = 0; TempChildList->get_length(&listCount); MSXML2::IXMLDOMNode *tempListItem = NULL; _variant_t tempValue; for(j = 0 ; j < listCount; j++) { TempChildList->get_item(j,&tempListItem); tempListItem->get_nodeTypedValue(&tempValue); strTemp.Format("%s",(char *)(_bstr_t)tempValue); strTemp = strTemp.TrimLeft(); strTemp = strTemp.TrimRight(); gPGisMainCtrlProc.m_BusinessManage_ConnectToGPSCheckServer.m_PatrolDevListData.AddItem(strTemp); if(isUpdateOnLineDeviceList) //当巡防路线修改时为TRUE,此时要更新在线终端的巡防状态字段 { gPGisMainCtrlProc.m_BusinessManage_ConToPub.Update_OnlineDeviceList_PatrolState(strTemp); // } TRACE("添加巡防用户信息 %s \n",strTemp); } } //end for(i = 0 bRet = TRUE; gWriteLogApp.WriteLog( FOR_ALARM,_T("%s [SYS] 加载巡防终端信息 %d 成功 \n"),CTime::GetCurrentTime().Format("%H:%M:%S"),tLen); m_bWebConnOK = TRUE; } } if(pStr) { delete []pStr; pStr = NULL; } } return bRet; }