TEST_FIXTURE(XmlFixture, CreateChild2) { MSXML2::IXMLDOMNode *node = 0; HRESULT hr = XMLHelper::CreateChild(root, &node, _T("test")); CHECK_OK(hr); CHECK(node); node->Release(); node = 0; BSTR query = SysAllocString(_T("//test")); MSXML2::IXMLDOMNodeList *nodeList = 0; hr = doc->selectNodes(query, &nodeList); SysFreeString(query); CHECK_OK(hr); CHECK(nodeList); long length = 0; hr = nodeList->get_length(&length); CHECK_OK(hr); CHECK_EQUAL(1, length); hr = nodeList->nextNode(&node); CHECK_OK(hr); CHECK(node); BSTR name = 0; hr = node->get_nodeName(&name); CHECK_OK(hr); CHECK_EQUAL(0, _tcscmp(name, _T("test"))); SysFreeString(name); }
int CTaskModel::CompleteChildCount() { int ret = 0; BSTR xpath = SysAllocString(_T(".//task")); MSXML2::IXMLDOMNodeList *pNodeList; HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList); if(pNodeList) { hr = pNodeList->get_length(reinterpret_cast<long *>(&ret)); if(hr != S_OK)ret = 0; } return ret; }
int CTaskModel::CountChildren() { long count = 0; MSXML2::IXMLDOMNodeList *pNodeList = 0; BSTR xpath = SysAllocString(_T("./task")); HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList); SysFreeString(xpath); if(pNodeList) { hr = pNodeList->get_length(&count); pNodeList->Release(); } return static_cast<int>(count); }
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; }