BOOL vmsMetalinkFile::ReadVerificationNode(IXMLDOMNode *pNode, vmsMetalinkFile_File *file) { IXMLDOMNodeListPtr spNodeList; pNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"hash") { vmsMetalinkFile_File_Hash hash; if (ReadHashNode (spItem, &hash)) file->vHashes.add (hash); } spItem = NULL; } return TRUE; }
VARIANT XMLDoc::getVariant(const XMLNodePtr &node, const TCHAR *tagName, int instans) { VARIANT result; result.vt = NULL; if(node!=NULL) { int i=0; for(XMLNodePtr p = node->firstChild; p != NULL; p = p->nextSibling) { if(p->nodeType==NODE_ELEMENT && _tcsicmp(((XMLElementPtr)p)->tagName,tagName) == 0 && i++ == instans) { IXMLDOMNodeListPtr childList = p->childNodes; LONG length; childList->get_length(&length); for(int j = 0; j < length; j++) { IXMLDOMNodePtr item; childList->get_item(j, &item); DOMNodeType itemType; item->get_nodeType(&itemType); if(itemType == NODE_TEXT) { item->get_nodeValue(&result); return result; } } return result; } } } return result; }
static void GetDeviceList(IXMLDOMElement* e, DEVICELIST& d) { HRESULT hr; IXMLDOMNodeListPtr list; long listlength; hr = e->get_childNodes(&list); if(hr!=S_OK) throw _com_error(hr); hr = list->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMNodePtr itemnode; IXMLDOMElementPtr itemlement; hr = list->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); itemlement = itemnode; DEVICE device; GetDevice(itemlement,device); d.push_back(device); } }
BOOL vmsMetalinkFile::ReadResourcesNode(IXMLDOMNode *pNode, vmsMetalinkFile_File *file) { IXMLDOMNodeListPtr spNodeList; pNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"url") { vmsMetalinkFile_File_Url url; if (ReadUrlNode (spItem, &url)) file->vMirrors.add (url); } spItem = NULL; } return TRUE; }
BOOL vmsMetalinkFile::ReadFilesNode(IXMLDOMNode *pFiles) { IXMLDOMNodeListPtr spNodeList; pFiles->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; BOOL bHasOkFileNode = FALSE; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"file") { if (ReadFileNode (spItem)) bHasOkFileNode = TRUE; } spItem = NULL; } return bHasOkFileNode; }
static void GetStrings(IXMLDOMElement* e, std::vector<std::wstring>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; std::wstring str; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"value"),&var); if(hr!=S_OK) throw _com_error(hr); str = (LPCWSTR)(_bstr_t)var; v.push_back(str); } }
static void GetGUIDs(IXMLDOMElement* e, std::vector<GUID>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; GUID guid; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"name"),&var); if(hr!=S_OK) throw _com_error(hr); string_to_guid((LPCWSTR)(_bstr_t)var,&guid); v.push_back(guid); } }
static void GetULongs(IXMLDOMElement* e,std::vector<unsigned long>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; unsigned long val; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"val"),&var); if(hr!=S_OK) throw _com_error(hr); val = (unsigned long)var; v.push_back(val); } }
static void GetGUIDLists(IXMLDOMElement* e,std::map<unsigned long,std::vector<GUID> >& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"id"),&var); if(hr!=S_OK) throw _com_error(hr); GetGUIDs(item,v[(unsigned long)var]); } }
BOOL vmsMetalinkFile::Parse(LPCSTR pszFile) { USES_CONVERSION; IXMLDOMDocumentPtr spXML; IXMLDOMNodePtr spNode; spXML.CreateInstance (__uuidof (DOMDocument)); if (spXML == NULL) return FALSE; spXML->put_async (FALSE); VARIANT_BOOL bRes; spXML->load (COleVariant (pszFile), &bRes); if (bRes == FALSE) return FALSE; spXML->selectSingleNode (L"metalink", &spNode); if (spNode == NULL) return FALSE; IXMLDOMNodeListPtr spNodeList; spNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; BOOL bHasOkFilesNode = FALSE; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"description") { CComBSTR bstrText; spItem->get_text (&bstrText); m_strDescription = W2A (bstrText); } else if (bstrName == L"files") { if (ReadFilesNode (spItem)) bHasOkFilesNode = TRUE; } spItem = NULL; } return bHasOkFilesNode; }
static void GetBDATemplateConnections(IXMLDOMElement* e,std::vector<BDA_TEMPLATE_CONNECTION>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; BDA_TEMPLATE_CONNECTION con; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"FromNodeType"),&var); if(hr!=S_OK) throw _com_error(hr); con.FromNodeType = (unsigned long)var; var.Clear(); hr = item->getAttribute(_bstr_t(L"FromNodePinType"),&var); if(hr!=S_OK) throw _com_error(hr); con.FromNodePinType = (unsigned long)var; var.Clear(); hr = item->getAttribute(_bstr_t(L"ToNodeType"),&var); if(hr!=S_OK) throw _com_error(hr); con.ToNodeType = (unsigned long)var; var.Clear(); hr = item->getAttribute(_bstr_t(L"ToNodePinType"),&var); if(hr!=S_OK) throw _com_error(hr); con.ToNodePinType = (unsigned long)var; var.Clear(); v.push_back(con); } }
void CXMLTree::InsetXMLNode(MSXML2::IXMLDOMNodePtr iNode, HTREEITEM hParentItem) { IXMLDOMNodeListPtr iChildren = iNode->childNodes; IXMLDOMNodePtr iChild = NULL; while ((iChild = iChildren->nextNode()) != NULL) { CString s((BSTR) iChild->nodeName); HTREEITEM i = InsertItem(s, hParentItem); iChild.AddRef(); SetItemData(i, (DWORD) (IXMLDOMNode *) iChild); //rekurze InsetXMLNode(iChild, i); } }
static void GetBDANodeDescriptors(IXMLDOMElement* e,std::vector<BDANODE_DESCRIPTOR>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item; IXMLDOMNodePtr itemnode; _variant_t var; BDANODE_DESCRIPTOR con; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"ulBdaNodeType"),&var); if(hr!=S_OK) throw _com_error(hr); con.ulBdaNodeType = (unsigned long)var; var.Clear(); hr = item->getAttribute(_bstr_t(L"guidFunction"),&var); if(hr!=S_OK) throw _com_error(hr); string_to_guid((LPCWSTR)(_bstr_t)var,&con.guidFunction); var.Clear(); hr = item->getAttribute(_bstr_t(L"guidName"),&var); if(hr!=S_OK) throw _com_error(hr); string_to_guid((LPCWSTR)(_bstr_t)var,&con.guidName); var.Clear(); } }
BOOL vmsMetalinkFile::ReadFileNode(IXMLDOMNode *pFile) { USES_CONVERSION; IXMLDOMNodeListPtr spNodeList; pFile->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; vmsMetalinkFile_File file; IXMLDOMNamedNodeMapPtr spAttrs; pFile->get_attributes (&spAttrs); if (spAttrs != NULL) { IXMLDOMNodePtr spFileName; spAttrs->getNamedItem (L"name", &spFileName); if (spFileName != NULL) { COleVariant vt; spFileName->get_nodeValue (&vt); ASSERT (vt.vt == VT_BSTR); if (vt.vt == VT_BSTR) file.strName = W2A (vt.bstrVal); } } IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"verification") { ReadVerificationNode (spItem, &file); } else if (bstrName == L"resources") { ReadResourcesNode (spItem, &file); } else if (bstrName == L"os") { CComBSTR bstrText; spItem->get_text (&bstrText); file.strOS = W2A (bstrText); } spItem = NULL; } if (file.vMirrors.size () == 0) return FALSE; m_vFiles.add (file); return TRUE; }
void CPageEvents::OnOK() { // Save any changes made to the currently-selected node's attributes UpdateNodeFromItem(m_lParamSelected); // Inspect the <Event> nodes of the document if (NULL != m_spXMLDoc) { // Get all of the <Event> nodes in the document IXMLDOMNodeListPtr spNodeList; VERIFY(SUCCEEDED(m_spXMLDoc->getElementsByTagName(m_bstrEvent, &spNodeList))); // Process each node IXMLDOMNodePtr spNode; do { // Get the next node of the child list VERIFY(SUCCEEDED(spNodeList->nextNode(&spNode))); if (NULL != spNode) { // Query for the IXMLDOMElement interface IXMLDOMElementPtr spElement(spNode); ASSERT(NULL != spElement); // Get the event id attribute CComVariant varEventID; spElement->getAttribute(m_bstrID, &varEventID); VERIFY(SUCCEEDED(varEventID.ChangeType(VT_I4))); AGCEventID idEventBegin = (AGCEventID)(V_UI4(&varEventID)); AGCEventID idEventEnd = (AGCEventID)(idEventBegin + 1); // Get the LogAsNTEvent attribute IXMLDOMAttributePtr spAttrNT; if (S_OK == spElement->getAttributeNode(m_bstrLogAsNTEvent, &spAttrNT)) { CComVariant varLog2NT; spAttrNT->get_value(&varLog2NT); VERIFY(SUCCEEDED(varLog2NT.ChangeType(VT_BOOL))); // Add this event id to the range, if it should be logged if (V_BOOL(&varLog2NT)) m_spRangesNT->AddByValues(idEventBegin, idEventEnd); } // Get the LogAsDBEvent attribute IXMLDOMAttributePtr spAttrDB; if (S_OK == spElement->getAttributeNode(m_bstrLogAsDBEvent, &spAttrDB)) { CComVariant varLog2DB; spAttrDB->get_value(&varLog2DB); VERIFY(SUCCEEDED(varLog2DB.ChangeType(VT_BOOL))); // Add this event id to the range, if it should be logged if (V_BOOL(&varLog2DB)) m_spRangesDB->AddByValues(idEventBegin, idEventEnd); } } } while (NULL != spNode); // Set the enabled ranges of the event logger object VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledNTEvents(m_spRangesNT))); VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledDBEvents(m_spRangesDB))); } // Perform default processing CPropertyPage::OnOK(); }
HRESULT CPageEvents::AddXMLNodeToTree(IXMLDOMNode* pNode, HTREEITEM hParent) { // Get the list of child nodes IXMLDOMNodeListPtr spChildren; RETURN_FAILED(pNode->get_childNodes(&spChildren)); // Process each child node IXMLDOMNodePtr spChild; do { // Get the next node of the child list RETURN_FAILED(spChildren->nextNode(&spChild)); if (NULL != spChild) { // Get the child node's tagname int iImage; CString strType; CString strID; bool bIsGroup, bIsEvent; CComBSTR bstrText; IXMLDOMElementPtr spElement(spChild); if (NULL != spElement) { CComBSTR bstrTagName; RETURN_FAILED(spElement->get_tagName(&bstrTagName)); if (bstrTagName.Length()) { // Accept the Event and EventGroup tag names if (0 == wcscmp(bstrTagName, m_bstrEvent)) { bIsGroup = false; bIsEvent = true; } else if (0 == wcscmp(bstrTagName, m_bstrEventGroup)) { bIsGroup = true; bIsEvent = false; } // Get the display attributes if this is a group or event node if (bIsGroup || bIsEvent) { // Get the type of the element CComBSTR bstrSeverity; GetElementSeverity(spElement, &bstrSeverity); iImage = ImageFromSeverity(bstrSeverity); strType = TypeFromSeverity(bstrSeverity); // Get the id of the element CComBSTR bstrID; GetElementID(spElement, &bstrID); strID = bstrID; // Get the name of the element RETURN_FAILED(GetElementDisplayName(spElement, &bstrText)); } } } // Add the node to the tree and list controls if (bstrText.Length()) { // Typecast the element pointer as an LPARAM IXMLDOMElement* pElement = spElement.Detach(); LPARAM lParam = reinterpret_cast<LPARAM>(pElement); // Insert the element into the tree USES_CONVERSION; LPCTSTR pszText = OLE2CT(bstrText); UINT mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; HTREEITEM hItem = m_tree.InsertItem(mask, pszText, iImage, iImage, 0, 0, lParam, hParent, TVI_LAST); // Insert the element into the list, if its not an <EventGroup> if (!bIsGroup) { int iItem = m_listEvents.GetItemCount(); iItem = m_listEvents.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, iItem, strType, 0, 0, iImage, lParam); if (-1 != iItem) { // Keep a reference on the element pointer in the LPARAM pElement->AddRef(); // Keep track of maximum widths int cx = m_listEvents.GetStringWidth(strType + " "); m_cxMaxType = max(m_cxMaxType, cx); cx = m_listEvents.GetStringWidth(strID + " "); m_cxMaxID = max(m_cxMaxID, cx); // Set the subitems m_listEvents.SetItem(iItem, 1, LVIF_TEXT, strID, 0, 0, 0, 0); m_listEvents.SetItem(iItem, 2, LVIF_TEXT, pszText, 0, 0, 0, 0); } } // Recurse into node, if it's a group if (bIsGroup) { RETURN_FAILED(AddXMLNodeToTree(spChild, hItem)); } } } } while (NULL != spChild); // Indicate success return S_OK; }
/**Read the XML config file. Currently contains keyboard choices.*/ void read_config_file() { TrainerConfig *result = new TrainerConfig(); CoInitialize(NULL); //read XML MSXML2::IXMLDOMDocumentPtr spXMLDoc; spXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60)); if (!spXMLDoc->load("ent-config.xml")) { write_text_to_log_file("No config found, using defaults"); config = result; //the default config } IXMLDOMNodeListPtr nodes = spXMLDoc->selectNodes(L"//ent-config/keys/key"); long length; nodes->get_length(&length); for (int i = 0; i < length; i++) { IXMLDOMNode *node; nodes->get_item(i, &node); IXMLDOMNamedNodeMap *attribs; node->get_attributes(&attribs); long length_attribs; attribs->get_length(&length_attribs); char *attrib_key_func = NULL; char *attrib_key_value = NULL; for (long j = 0; j < length_attribs; j++) { IXMLDOMNode *attribNode; attribs->get_item(j, &attribNode); attribNode->get_nodeName(&bstr); if (wcscmp(bstr, L"function") == 0) { VARIANT var; VariantInit(&var); attribNode->get_nodeValue(&var); attrib_key_func = _com_util::ConvertBSTRToString(V_BSTR(&var)); } else if (wcscmp(bstr, L"value") == 0) { VARIANT var; VariantInit(&var); attribNode->get_nodeValue(&var); attrib_key_value = _com_util::ConvertBSTRToString(V_BSTR(&var)); } SysFreeString(bstr); attribNode->Release(); } if (attrib_key_func != NULL && attrib_key_value != NULL) { result->get_key_config()->set_key(attrib_key_func, attrib_key_value); } delete attrib_key_func; delete attrib_key_value; attribs->Release(); node->Release(); } //nodes->Release(); //don't do this, it crashes on exit spXMLDoc.Release(); CoUninitialize(); config = result; }
/****************************************************************************** Function Name : nLoadHeader Input(s) : MSXML2::IXMLDOMNodePtr& pHeaderDOMNode Output : INT Functionality : Retrieves the Header info Member of : CTestSetupEntity Friend of : - Author(s) : Venkatanarayana Makam Date Created : 06/04/2011 Modifications : Codetag : ******************************************************************************/ INT CTestSetupEntity::nLoadHeader(MSXML2::IXMLDOMNodePtr& pHeaderDOMNode) { // CComPtr<IXMLDOMNode> pHeaderDOMNode; MSXML2::IXMLDOMNodeListPtr pXMLDOMInfoList; MSXML2::IXMLDOMNodePtr pInfoNode; MSXML2::IXMLDOMNodePtr pInfoCategoryNode; MSXML2::IXMLDOMNodePtr pInfoValueNode; _bstr_t bstrNodeName = "info"; CComVariant NodeValue; pXMLDOMInfoList = pHeaderDOMNode->selectNodes(bstrNodeName); LONG lCount = 0; pXMLDOMInfoList->get_length(&lCount); SInfo ouTempSInfo; for(int i = 0; i<lCount; i++) { pInfoNode = pXMLDOMInfoList->Getitem(i); //bstrNodeName = def_STR_CATEGORY_NODE; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_CATEGORY_NODE))); pInfoCategoryNode = pInfoNode->selectSingleNode(bstrNodeName); pInfoCategoryNode->get_nodeTypedValue(&NodeValue); ouTempSInfo.m_omCategory = strCopyBSTRToCString(NodeValue); pInfoCategoryNode.Release(); //bstrNodeName = def_STR_VALUE_NODE; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_VALUE_NODE))); pInfoCategoryNode = pInfoNode->selectSingleNode(bstrNodeName); pInfoCategoryNode->get_nodeTypedValue(&NodeValue); ouTempSInfo.m_omValue = strCopyBSTRToCString(NodeValue); pInfoCategoryNode.Release(); pInfoNode.Release(); if(ouTempSInfo.m_omCategory == def_STR_MODULENAME) { m_ouTestSetupHeader.m_sModuleName.m_omCategory = ouTempSInfo.m_omCategory; m_ouTestSetupHeader.m_sModuleName.m_omValue = ouTempSInfo.m_omValue; } if(ouTempSInfo.m_omCategory == def_STR_ENGINEERNAME) { m_ouTestSetupHeader.m_sEngineerInfo1.m_omCategory = ouTempSInfo.m_omCategory; m_ouTestSetupHeader.m_sEngineerInfo1.m_omValue = ouTempSInfo.m_omValue; } if(ouTempSInfo.m_omCategory == def_STR_ENGINERROLE) { m_ouTestSetupHeader.m_sEngineerInfo2.m_omCategory = ouTempSInfo.m_omCategory; m_ouTestSetupHeader.m_sEngineerInfo2.m_omValue = ouTempSInfo.m_omValue; } if(ouTempSInfo.m_omCategory == def_STR_VERSION) { m_ouTestSetupHeader.m_sVersion.m_omCategory = ouTempSInfo.m_omCategory; m_ouTestSetupHeader.m_sVersion.m_omValue = ouTempSInfo.m_omValue; } } //Taking Database long lCount2 = 0; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_LISTOFDB))); IXMLDOMNodeListPtr pIDOMSignalList = pHeaderDOMNode->selectNodes(bstrNodeName); pIDOMSignalList->get_length(&lCount2); for(INT j = 0; j < lCount2; j++) { IXMLDOMNode* pIDOMSChildSignal; pIDOMSignalList->get_item(j, &pIDOMSChildSignal); pIDOMSChildSignal->get_nodeTypedValue(&NodeValue); m_ouTestSetupHeader.m_omDatabasePaths.Add(strCopyBSTRToCString(NodeValue)); //Set The Database Paths SetDatabaseFile(strCopyBSTRToCString(NodeValue), j+1); } // pInfoNode.Release(); //bstrNodeName = def_STR_REPORT_FORMAT; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_FORMAT))); pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName); pInfoNode->get_nodeTypedValue(&NodeValue); CString omStrExt; omStrExt = strCopyBSTRToCString(NodeValue); pInfoNode.Release(); if(omStrExt == "HTM") { m_ouTestSetupHeader.m_sReportFile.m_eType = HTM; } else { m_ouTestSetupHeader.m_sReportFile.m_eType = TXT; } //bstrNodeName = def_STR_REPORT_PATH; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_PATH))); pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName); pInfoNode->get_nodeTypedValue(&NodeValue); m_ouTestSetupHeader.m_sReportFile.m_omPath = strCopyBSTRToCString(NodeValue); pInfoNode.Release(); //bstrNodeName = def_STR_REPORT_TIMEMODE; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_TIMEMODE))); pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName); pInfoNode->get_nodeTypedValue(&NodeValue); CString strTemp; strTemp = strCopyBSTRToCString(NodeValue); if(strTemp == "ABS") { m_ouTestSetupHeader.m_sReportFile.m_eTimeMode = ABS; } else //Default { m_ouTestSetupHeader.m_sReportFile.m_eTimeMode = REL; } pInfoNode.Release(); //bstrNodeName = def_STR_BUS_TYPE; bstrNodeName.Assign(SysAllocString(CT2W(def_STR_BUS_TYPE))); pInfoNode= pHeaderDOMNode->selectSingleNode(bstrNodeName); pInfoNode->get_nodeTypedValue(&NodeValue); strTemp = strCopyBSTRToCString(NodeValue); if(strTemp == "CAN") { m_ouTestSetupHeader.m_eBus = CAN; } pInfoNode.Release(); return 0; }
/****************************************************************************** Function Name : GetData Input(s) : MSXML2::IXMLDOMNodePtr& pIDomNode Output : HRESULT Functionality : Fill the datastructure from xml node pIDomNode Member of : CVerify_MessageEntity Friend of : - Author(s) : Venkatanarayana Makam, GT-Derka Date Created : 06/04/2011 Modifications : ******************************************************************************/ HRESULT CVerify_MessageEntity::GetData(MSXML2::IXMLDOMNodePtr& pIDomNode) { IXMLDOMNode* pIDOMChildNode; LONG lCount; CComBSTR bstrNodeName; CComVariant NodeValue; CString omstrTemp; CSignalCondition ouSignalCondition; IXMLDOMNamedNodeMapPtr pIDOMAttributes; pIDOMAttributes = pIDomNode->Getattributes();// get_attributes((IXMLDOMNamedNodeMap**)&pIDOMAttributes); //Retrieving Message ID bstrNodeName = def_STR_TCATTRIB_ID; pIDOMAttributes->getNamedItem(bstrNodeName, &pIDOMChildNode); pIDOMChildNode->get_nodeTypedValue(&NodeValue); omstrTemp = strCopyBSTRToCString(NodeValue); m_ouData.m_dwMessageID = atoi((LPCSTR)omstrTemp); m_ouData.m_omMessageName = omstrTemp; if(m_ouDataBaseManager.bIsValidMessageID(m_ouData.m_dwMessageID)== FALSE) { //TODO::INVALID MSG POSSIBLE ONLY WHEN THE FILE IS EDITED WITH NOTEPAD. return -1; } pIDOMChildNode->Release(); //Retrieving Message UNIT bstrNodeName = _(def_STR_TCATTRIB_UNIT); pIDOMAttributes->getNamedItem(bstrNodeName, &pIDOMChildNode); pIDOMChildNode->get_nodeTypedValue(&NodeValue); omstrTemp = strCopyBSTRToCString(NodeValue); if(omstrTemp == "RAW") { m_ouData.m_eSignalUnitType = RAW; } else // else if(omstrTemp == "ENG") { m_ouData.m_eSignalUnitType = ENG; } pIDOMChildNode->Release(); //Retrieving Message Channel bstrNodeName = def_STR_TCATTRIB_CHANNEL; pIDOMAttributes->getNamedItem(bstrNodeName, &pIDOMChildNode); m_ouData.m_byChannelNumber = 0; // set default-value for the case, the number is incorrect or the whole argument is missing if (NULL != pIDOMChildNode) // avoid crash in case XML-file -without channel-information- is loaded { pIDOMChildNode->get_nodeTypedValue(&NodeValue); omstrTemp = strCopyBSTRToCString(NodeValue); m_ouData.m_byChannelNumber = atoi((LPCSTR)omstrTemp); pIDOMChildNode->Release(); } if(m_ouData.m_byChannelNumber == 0) // if casting fails (failure in xml) { m_ouData.m_byChannelNumber = 1; // set default channel */ m_lDefaultChannelUsed = 1; } //Retrieving Signals and their Data IFrame* sMsg; IXMLDOMNodeListPtr pIDOMSignalList; IXMLDOMNode* pIDOMSChildSignal; bstrNodeName = _(def_STR_SIGNAL_NODE); pIDOMSignalList = pIDomNode->selectNodes((_bstr_t)bstrNodeName); pIDOMSignalList->get_length(&lCount); INT nRetVal; nRetVal = m_ouDataBaseManager.nGetMessageName(m_ouData.m_dwMessageID, m_ouData.m_omMessageName); if(nRetVal != S_OK) { return nRetVal; } nRetVal = m_ouDataBaseManager.nGetMessageInfo(m_ouData.m_omMessageName, &sMsg); if ( sMsg == nullptr ) { return nRetVal; } UINT unSignalCount = sMsg->GetSignalCount(); //W4 Removal - Local variable not required //UINT unTSSignalCount = lCount; std::map<ISignal*, SignalInstanse> signalList; sMsg->GetSignalList( signalList); std::string signalName; for (auto signal : signalList ) //for(UINT i = 0; i < unSignalCount; i++) { CSignalCondition ouSignalData, ouTSSignalData; signal.first->GetName( signalName ); ouSignalData.m_omSigName = signalName.c_str(); ouSignalData.m_omCondition = ""; for(int i = 0; i < lCount; i++) { pIDOMSignalList->get_item(i, &pIDOMSChildSignal); vRetrieveConditionSignalValue(pIDOMSChildSignal, ouTSSignalData); if(ouSignalData.m_omSigName == ouTSSignalData.m_omSigName) { ouSignalData.m_omCondition = ouTSSignalData.m_omCondition; break; } } m_ouData.m_odSignalConditionList.AddTail(ouSignalData); } return S_OK; }
void ProcessRSSItem(RSSFeed* f) { CoInitializeEx(0, COINIT_APARTMENTTHREADED); try { IXMLDOMDocumentPtr ptr("Microsoft.FreeThreadedXMLDOM"); ptr->async = VARIANT_FALSE; ptr->validateOnParse = VARIANT_FALSE; ptr->load(f->link); if (ptr != 0) { IXMLDOMNodeListPtr nodes = ptr->selectNodes(_bstr_t("/rss/channel/item")); if (nodes != 0) { int nItems = nodes->Getlength(); // printf("%d headlines\n", nItems); for (int i = 0; i < nItems; i++) { _bstr_t xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; xml += "<rss version=\"0.92\">\n"; xml += "<channel>\n"; xml += "<item>\n"; IXMLDOMNodePtr node = nodes->Getitem(i); _bstr_t title = GetPathValue(node, _bstr_t("title")); xml += "<title>"; xml += title; xml += "</title>\n"; _bstr_t link = GetPathValue(node, _bstr_t("link")); xml += "<link>"; xml += link; xml += "</link>\n"; _bstr_t description = GetPathValue(node, _bstr_t("description")); xml += "<description>"; xml += description; xml += "</description>\n"; xml += "</item>\n"; xml += "</channel>\n"; xml += "</rss>\n"; Message m; m.Set("do_method", "notify"); m.Set("kn_to", "/headlines"); m.Set("title", (const char*)title); m.Set("link", (const char*)link); m.Set("description", (const char*)description); m.Set("kn_payload", (const char*)xml); m.Set("kn_id", (const char*)ConvertLinkToId(link)); m.Set("source_title", (const char*)f->title); m.Set("source_link", (const char*)f->link); m.Set("source_description", (const char*)f->description); m.Set("displayname", "RSS"); m.Set("rss_source", (const char*)f->title); m.Set("rss_link", (const char*)link); m.Set("rss_title", (const char*)title); m.Set("rss_description", (const char*)description); g_Conn.Publish(m, 0); // printf("%d: %s <%s>\n", i, (const char*)title, (const char*)link); } } } } catch (...) { } CoUninitialize(); }
bool GetXmlValue( const IXMLDOMDocumentPtr& pXMLDOMDocument, const CComBSTR& bstrTagName, const CComBSTR& bstrAttributeName, std::vector<CComBSTR>& rvbstrValue ) { // アウトプットの初期化 rvbstrValue.clear(); // インプットのチェック if( 0 == bstrTagName.Length() ) { return false; } HRESULT hResult; // タグ名のノードリストの取得 IXMLDOMNodeListPtr pXMLDOMNodeList = NULL; hResult = pXMLDOMDocument->getElementsByTagName( bstrTagName, &pXMLDOMNodeList ); if( FAILED(hResult) || NULL == pXMLDOMNodeList ) { assert( !"タグ名のノードリストの取得に失敗" ); return false; } // ノードリストのノードの数の取得 long lCountNode = 0; hResult = pXMLDOMNodeList->get_length( &lCountNode ); if( FAILED(hResult) ) { assert( !"ノードリストのノードの数の取得に失敗" ); return false; } // ノードリストのノード一つずつ処理 for( int i = 0; i < lCountNode; ++i ) { // ノードリストのうちの一つのノードの取得 IXMLDOMNodePtr pXMLDOMNode = NULL; hResult = pXMLDOMNodeList->get_item( i, &pXMLDOMNode ); if( FAILED(hResult) ) { assert( !"ノードリストのうちの一つのノードの取得に失敗" ); return false; } // ノードタイプの取得 DOMNodeType eNodeType; hResult = pXMLDOMNode->get_nodeType( &eNodeType ); if( FAILED(hResult) ) { assert( !"ノードタイプの取得に失敗" ); return false; } if( NODE_ELEMENT != eNodeType ) { assert( !"ノードタイプがエレメントでないのはおかしい" ); return false; } // エレメント型への変換 IXMLDOMElementPtr pXMLDOMElement = NULL; hResult = pXMLDOMNode->QueryInterface( IID_IXMLDOMElement, (void**)&pXMLDOMElement ); // スマートポインタ型を利用しているので、pXMLDOMElement = pXMLDOMNode; でも良い。 if( FAILED(hResult) || NULL == pXMLDOMElement ) { assert( !"エレメント型への変換に失敗" ); return false; } // 属性値の取得か、データ値の取得か if( bstrAttributeName.Length() ) { // 属性値の取得 IXMLDOMAttribute* pAttributeNode = NULL; CComVariant varValue; hResult = pXMLDOMElement->getAttribute( bstrAttributeName, &varValue ); if( SUCCEEDED(hResult) && VT_BSTR == varValue.vt ) { rvbstrValue.push_back( varValue.bstrVal ); } } else { // データ値の取得 CComBSTR bstrText; hResult = pXMLDOMElement->get_text( &bstrText ); if( SUCCEEDED(hResult) ) { rvbstrValue.push_back( bstrText ); } } } return true; }
static void GetPininfos(IXMLDOMElement* e,std::vector<PININFO>& v) { HRESULT hr; IXMLDOMNodeListPtr children; long listlength; hr = e->get_childNodes(&children); if(hr!=S_OK) throw _com_error(hr); hr = children->get_length(&listlength); if(hr!=S_OK) throw _com_error(hr); for(size_t n=0;n<listlength;n++) { IXMLDOMElementPtr item, item2; IXMLDOMNodePtr itemnode, itemnode2; _variant_t var; PININFO pininfo; hr = children->get_item(n,&itemnode); if(hr!=S_OK) throw _com_error(hr); item = itemnode; hr = item->getAttribute(_bstr_t(L"ksproperty_pin_category"),&var); if(hr==S_OK) { string_to_guid((LPCWSTR)(_bstr_t)var,&pininfo.category); pininfo.category_valid = true; var.Clear(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_cinstances"),&itemnode2); if(hr==S_OK) { item2 = itemnode2; hr = item2->getAttribute(_bstr_t(L"PossibleCount"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.cinstances.PossibleCount = (unsigned long)var; var.Clear(); hr = item2->getAttribute(_bstr_t(L"CurrentCount"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.cinstances.CurrentCount = (unsigned long)var; var.Clear(); pininfo.cinstances_valid = true; itemnode2.Release(); item2.Release(); } hr = item->getAttribute(_bstr_t(L"ksproperty_pin_communication"),&var); if(hr==S_OK) { pininfo.communication = (KSPIN_COMMUNICATION)(unsigned long)var; pininfo.communication_valid = true; var.Clear(); } hr = item->getAttribute(_bstr_t(L"ksproperty_pin_dataflow"),&var); if(hr==S_OK) { pininfo.dataflow = (KSPIN_DATAFLOW)(unsigned long)var; pininfo.dataflow_valid = true; var.Clear(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_dataintersection"),&itemnode2); if(hr == S_OK) { item2 = itemnode2; GetKSDATARANGE(item2,pininfo.dataintersection); pininfo.dataintersection_valid = true; itemnode2.Release(); item2.Release(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_dataranges"),&itemnode2); if(hr==S_OK) { IXMLDOMNodeListPtr children2; long listlength2; item2 = itemnode2; hr = item2->get_childNodes(&children2); if(hr!=S_OK) throw _com_error(hr); hr = children2->get_length(&listlength2); if(hr!=S_OK) throw _com_error(hr); for(size_t m=0;m<listlength2;m++) { IXMLDOMElementPtr item3; IXMLDOMNodePtr itemnode3; KSDATARANGE ksdatarange; hr = children2->get_item(m, &itemnode3); if(hr!=S_OK) throw _com_error(hr); item3 = itemnode3; GetKSDATARANGE(item3,ksdatarange); pininfo.dataranges.push_back(ksdatarange); } item2.Release(); itemnode2.Release(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_globalcinstances"),&itemnode2); if(hr==S_OK) { item2 = itemnode2; hr = item2->getAttribute(_bstr_t(L"PossibleCount"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.globalcinstances.PossibleCount = (unsigned long)var; var.Clear(); hr = item2->getAttribute(_bstr_t(L"CurrentCount"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.globalcinstances.CurrentCount = (unsigned long)var; var.Clear(); pininfo.globalcinstances_valid = true; itemnode2.Release(); item2.Release(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_interfaces"),&itemnode2); if(hr==S_OK) { IXMLDOMNodeListPtr children2; long listlength2; item2 = itemnode2; hr = item2->get_childNodes(&children2); if(hr!=S_OK) throw _com_error(hr); hr = children2->get_length(&listlength2); if(hr!=S_OK) throw _com_error(hr); for(size_t m=0;m<listlength2;m++) { IXMLDOMElementPtr item3; IXMLDOMNodePtr itemnode3; KSIDENTIFIER ksidentifier; hr = children2->get_item(m, &itemnode3); if(hr!=S_OK) throw _com_error(hr); item3 = itemnode3; GetKSIDENTIFIER(item3,ksidentifier); pininfo.interfaces.push_back(ksidentifier); } itemnode2.Release(); item2.Release(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_mediums"),&itemnode2); if(hr==S_OK) { IXMLDOMNodeListPtr children2; long listlength2; item2 = itemnode2; hr = item2->get_childNodes(&children2); if(hr!=S_OK) throw _com_error(hr); hr = children2->get_length(&listlength2); if(hr!=S_OK) throw _com_error(hr); for(size_t m=0;m<listlength2;m++) { IXMLDOMElementPtr item3; IXMLDOMNodePtr itemnode3; KSIDENTIFIER ksidentifier; hr = children2->get_item(m, &itemnode3); if(hr!=S_OK) throw _com_error(hr); item3 = itemnode3; GetKSIDENTIFIER(item3,ksidentifier); pininfo.mediums.push_back(ksidentifier); } itemnode2.Release(); item2.Release(); } hr = item->getAttribute(_bstr_t(L"ksproperty_pin_name"),&var); if(hr==S_OK) { pininfo.name = (LPCWSTR)(_bstr_t)var; var.Clear(); } hr = item->getAttribute(_bstr_t(L"ksproperty_pin_necessaryinstances"),&var); if(hr==S_OK) { pininfo.necessaryinstances = (unsigned long)var; pininfo.necessaryinstances_valid = true; var.Clear(); } hr = item->selectSingleNode(_bstr_t(L"ksproperty_pin_physicalconnection"),&itemnode2); if(hr==S_OK) { item2 = itemnode2; hr = item2->getAttribute(_bstr_t(L"Size"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.physicalconnection.Size = (unsigned long)var; var.Clear(); hr = item2->getAttribute(_bstr_t(L"Pin"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.physicalconnection.Pin = (unsigned long)var; var.Clear(); hr = item2->getAttribute(_bstr_t(L"SymbolicLinkName"),&var); if(hr!=S_OK) throw _com_error(hr); pininfo.symboliclinkname = (LPCWSTR)(_bstr_t)var; var.Clear(); pininfo.physicalconnection_valid = true; itemnode2.Release(); item2.Release(); } v.push_back(pininfo); } }