void XmlParser::Parse(NodeCallback callback, void *data)
{
	MSXML2::IXMLDOMNodeListPtr NodeListPtr;
	BSTR strFindText  = L" ";
	MSXML2::IXMLDOMNode *pIDOMNode = NULL;
	BSTR bstrNodeType;

	assert(m_domDocument != NULL);

	NodeListPtr = m_domDocument->getElementsByTagName(strFindText);	

	for(int i = 0; i < NodeListPtr->length; i++)
	{
		if (pIDOMNode)
			pIDOMNode->Release();

		NodeListPtr->get_item(i, &pIDOMNode);
		pIDOMNode->get_nodeTypeString(&bstrNodeType);

		if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"element") != 0)
			continue;
		
		XmlNode node;
		_parseNode(pIDOMNode, node);
		
		if (callback(node, data) == false)
			break;
	}

	if (pIDOMNode)
			pIDOMNode->Release();	
}
Exemple #2
0
CA_API UINT __stdcall Xml_DeleteNodes(MSIHANDLE hInstall)
{
    MSI_EXCEPTION_HANDLER_PROLOG;
    MsiInstall msiInstall(hInstall);

    std::wstring filename = msiInstall.GetProperty(L"XML_FILENAME");
    AppSecInc::Xml::XmlDocument doc;
    doc.Load(filename);

    std::wstring xpath = msiInstall.GetProperty(L"XML_XPATH");
    MSXML2::IXMLDOMNodeListPtr nodes = doc.FindNodes(xpath);
    int count = 0;
    if (NULL != nodes)
    {
        MSXML2::IXMLDOMNodePtr node = NULL;
        while (NULL != (node = nodes->nextNode()))
        {
            node->parentNode->removeChild(node);
            count++;
        }
    }

    if (count > 0)
    {
        CHECK_HR(doc->save(CComVariant(filename.c_str())),
                 L"Error saving '" << filename << L"'");
    }

    msiInstall.SetProperty(L"XML_DELETED", AppSecInc::StringUtils::toWString(count));
    MSI_EXCEPTION_HANDLER_EPILOG;
    return ERROR_SUCCESS;
}
//遍历指定节点列表的数据
BOOL CXmlBase::FetchNodeList(LPCTSTR lpszXmlPathFile, LPCTSTR lpszNamespace
	, LPCTSTR lpszNodeListXPath, DWORD dwFlag)
{
	MSXML2::IXMLDOMDocument2Ptr pDoc = NULL;
	MSXML2::IXMLDOMNodeListPtr pNodeList = NULL;
	MSXML2::IXMLDOMNodePtr pNode = NULL;
	long lNodeCount = 0;
	HRESULT hr = S_OK;

	if (!IsAccessibleFile(lpszXmlPathFile)) return FALSE;

	pDoc = GetXmlDocPtrByFile(lpszXmlPathFile, lpszNamespace);
	if (pDoc == NULL) return FALSE;

	pNodeList = GetNodeListPtr(lpszNodeListXPath, pDoc);
	if (pNodeList == NULL) return FALSE;

	lNodeCount = pNodeList->Getlength();
	for (int i=0; i<lNodeCount; i++)
	{
		hr = pNodeList->get_item(i, &pNode);
		if (FAILED(hr) || NULL == pNode) return FALSE;
		if (!OnFetchNodeList(pNode, dwFlag)) return FALSE;
	}
	return TRUE;//(lNodeCount != 0);
}
//遍历指定节点列表的数据
BOOL CXmlBase::FetchNodeList2(MSXML2::IXMLDOMNodePtr pParentNode, DWORD dwFlag)
{
	MSXML2::IXMLDOMNodeListPtr pNodeList = NULL;
	MSXML2::IXMLDOMNodePtr pNode = NULL;
	long lNodeCount = 0;
	HRESULT hr = S_OK;

	if (NULL == pParentNode)
	{
		return FALSE;
	}
	pNodeList = GetNodeListPtr(pParentNode);
	if (pNodeList == NULL)
	{
		return FALSE;
	}

	lNodeCount = pNodeList->Getlength();
	for (long i=0; i<lNodeCount; i++)
	{
		hr = pNodeList->get_item(i, &pNode);
		if (FAILED(hr) || NULL == pNode)
		{
			return FALSE;
		}
		if (!OnFetchNodeList2(pNode, dwFlag))
		{
			return FALSE;
		}
	}
	return TRUE;
}
Exemple #5
0
// 获取当前节点的最后一个Element子节点
IBpXMLNode* CBpXMLNode::GetLastElementChild() const
{
	if (m_pDOMNode == NULL)
		return NULL;

	if (m_pDOMNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
	{ 
		MSXML2::IXMLDOMNodeListPtr pNodeList = m_pDOMNode->GetchildNodes(); 
		if (pNodeList == NULL)
			return NULL;
		long nListLen = 0;
		pNodeList->get_length(&nListLen);;
		MSXML2::IXMLDOMNodePtr pNode = NULL;
		for (long i = 0; i < nListLen; i++) 
		{ 
			pNodeList->get_item(nListLen - 1 - i, &pNode); 
			if (pNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
			{ 
				CBpXMLNode *pNodeCreated  = new CBpXMLNode();	
				pNodeCreated->m_pDOMNode = pNode;
				return (IBpXMLNode*)pNodeCreated;
			} 
		} 
	}
	return NULL;
}
MTConnectDataModel MTConnectDeviceParser::ReadDeviceDescription(std::string filename)
{
	MTConnectDataModel dataItems;
	dataItems.clear();
	if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES)
	{
		filename= ::ExeDirectory() + filename;
	}
	if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES)
		throw std::exception("MTConnectDeviceParser::ReadDeviceDescription invalid devices file");

	_devicesfilename = filename;

	try{
		ParseXMLDocument(_devicesfilename.c_str());

		MSXML2::IXMLDOMNodePtr root = m_pXMLDoc->GetdocumentElement();
		MSXML2::IXMLDOMNodeListPtr nodes = root->selectNodes(_bstr_t("//DataItem"));
		for(int i=0; i< nodes->length; i++)
		{
			MSXML2::IXMLDOMNodePtr pNode = NULL;	
			CDataItem dataItem;
			nodes->get_item(i, &pNode);

			dataItem.name = (LPCSTR)  GetAttribute(pNode, "name");
			dataItem.category = (LPCSTR) GetAttribute(pNode, "category");
			dataItem.id = (LPCSTR) GetAttribute(pNode, "id");
			dataItem.type = (LPCSTR) GetAttribute(pNode, "type");
			dataItem.subType = (LPCSTR) GetAttribute(pNode, "subType");
			dataItem.units = (LPCSTR) GetAttribute(pNode, "units");
			dataItem.nativeUnits = (LPCSTR) GetAttribute(pNode, "nativeUnits");
			if(dataItem.type == "ASSET_CHANGED")
			{
				dataItem.category = "ASSET_CHANGED";
			}

			dataItem.category=MakeLower(dataItem.category);
			
			if(!dataItem.name.empty())
			{
				dataItems[dataItem.name]=dataItem;
			}
			// Could get name or id via SHDR
			else if(!dataItem.id.empty())
			{
				dataItems[dataItem.id]=dataItem;
			}
			else
			{
				continue;
			}
		}
	}
	catch(_com_error error)
	{
		std::cout << "MTConnectDeviceParser::ReadDeviceDescription" << error.ErrorMessage();
	}
	return dataItems;

}
void CSimpleFilterDialog::SaveSelection(void)
{
	POSITION pos = m_ResultList.GetFirstSelectedItemPosition(); 

	
	//okopiruje vzorovy element selection
	MSXML2::IXMLDOMElementPtr selection_elem = m_active_element->ownerDocument->createElement("selection");
	MSXML2::IXMLDOMAttributePtr id_attr = m_active_element->ownerDocument->createAttribute("id");
	selection_elem->setAttributeNode(id_attr);
	id_attr.Release();
	
	//vymaze vsechny selection
	MSXML2::IXMLDOMNodeListPtr list = m_cloned_active_element->selectNodes("filter[@type='simple']/selection");
	MSXML2::IXMLDOMSelection * sel;
	list.QueryInterface(__uuidof(MSXML2::IXMLDOMSelection), &sel);
	sel->removeAll();
	sel->Release();

	MSXML2::IXMLDOMNodePtr filter = m_cloned_active_element->selectSingleNode("filter[@type='simple']");
	
	while (pos)
	{
		int nItem = m_ResultList.GetNextSelectedItem(pos);

		selection_elem->setAttribute("id", (LPCTSTR) m_ResultList.GetItemText(nItem, 0));
		filter->appendChild(selection_elem->cloneNode(VARIANT_FALSE));
	}

	selection_elem.Release();

}
/******************************************************************************
Function Name  :  nLoadTestCases
Input(s)       :  MSXML2::IXMLDOMNodePtr& pTSDOM
Output         :  INT
Functionality  :
Member of      :  CTestSetupEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam, GT-Derka
Date Created   :  06/04/2011
Modifications  :
Codetag        :  CS004
******************************************************************************/
INT CTestSetupEntity::nLoadTestCases(MSXML2::IXMLDOMNodePtr& pTSDOM)
{
    LONG lDefaultChannelUsed = 0;
    LONG lCount;
    _bstr_t bstrNodeName(def_STR_TESTCASE_NODE);

    MSXML2::IXMLDOMNodeListPtr pDOMTCNodeList;
    MSXML2::IXMLDOMNodePtr pIXMLDOMTestCase;
    pDOMTCNodeList = pTSDOM->selectNodes(bstrNodeName);
    pDOMTCNodeList->get_length(&lCount);
    for(int i=0; i<lCount; i++)
    {
        CTestCaseEntity odTestCaseEntity;

        pIXMLDOMTestCase = pDOMTCNodeList->Getitem(i);
        odTestCaseEntity.GetData(pIXMLDOMTestCase);
        m_odTestCaseEntityList.AddTail(odTestCaseEntity);
        lDefaultChannelUsed += odTestCaseEntity.m_lDefaultChannelUsed;
    }
    if(lDefaultChannelUsed == 1)
    {
        AfxMessageBox(_("1 entity without channel-information loaded.\nCAN-Channel 1 selected."), MB_OK | MB_ICONINFORMATION );
    }
    else if(lDefaultChannelUsed > 1)
    {
        CString str;
        str.Format("%d", lDefaultChannelUsed);
        AfxMessageBox(str + _(" entities without channel-information loaded.\nCAN-Channel 1 selected in each case."), MB_OK | MB_ICONINFORMATION );
    }
    return S_OK;

}
Exemple #9
0
int CXMLParser3::GetNodeText_len(LPCTSTR strNodeName,TCHAR *pDestBuffer,int nNode/*=0*/)
{
	try
	{
		HRESULT hr;
		MSXML2::IXMLDOMNodeListPtr List = m_pXMLDom->getElementsByTagName((_bstr_t)strNodeName);
		long lNodesCount = 0;
		hr = List->get_length(&lNodesCount);
		if(SUCCEEDED(hr) && (nNode<lNodesCount ))
		{
			MSXML2::IXMLDOMNodePtr Node = List->item[nNode];
			int nLen = _tcslen(Node->text);
			if(pDestBuffer==NULL)
			{
				pDestBuffer = new TCHAR[nLen+1];
			}
			_tcscpy(pDestBuffer,Node->text);
			pDestBuffer[nLen+1]='\0';
			return nLen;
		}
		return 0;
	}
	catch (_com_error &e)
	{
		m_nError = e.Error();
		m_strError = e.ErrorMessage();
		return 0;
	}
	catch (...)
	{
	}
	return 0;
}
Exemple #10
0
	void readVerticesNormalsTexcoords(MSXML2::IXMLDOMNodePtr mesh, geometry_t &geometry)
	{
		MSXML2::IXMLDOMNodeListPtr sourceList = mesh->selectNodes("r:source");
		vector<float> vertices;
		vector<float> normals;
		vector<float> texcoords;

		for (int i = 0; i < sourceList->length; i++)
		{
			MSXML2::IXMLDOMNodePtr source = sourceList->Getitem(i);
			MSXML2::IXMLDOMNamedNodeMapPtr attributes = source->attributes;

			for (int j = 0; j < attributes->length; j++)
			{
				_bstr_t attributeName = attributes->getNamedItem("id")->text;

				if (wcsstr(_wcslwr(attributeName), L"position"))
				{
					geometry.vertices = readArray<float>(source);
				} else if (wcsstr(_wcslwr(attributeName), L"normal"))
				{
					geometry.normals = readArray<float>(source);
				} else if (wcsstr(_wcslwr(attributeName), L"map") ||	// belnder
						   wcsstr(_wcslwr(attributeName), L"-uv"))		// 3dsmax
				{
					geometry.texcoords = readArray<float>(source);
				}
			}
		}
	}
Exemple #11
0
CA_API UINT __stdcall TemplateFiles_Deferred(MSIHANDLE hInstall)
{
	MSI_EXCEPTION_HANDLER_PROLOG;
    MsiInstall msiInstall(hInstall);

    AppSecInc::Xml::XmlDocument xmlDocument;
    xmlDocument.LoadXml(msiInstall.GetActionData());

    MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"//TemplateFile[@execute='true']"); // \todo //Row[@rollback='false']
    MSXML2::IXMLDOMNodePtr row = NULL;
    while (NULL != (row = rows->nextNode()))
    {
        std::wstring id = xmlDocument.GetAttributeValue(L"id", row);
        std::wstring source = xmlDocument.GetNodeValue(L"Source", row);
        std::wstring target = xmlDocument.GetNodeValue(L"Target", row, source);

		msiInstall.LogInfo(L"TemplateFiles_Deferred", source + L" => " + target);

        std::map<std::wstring, std::wstring> properties;

        {
            MSXML2::IXMLDOMNodeListPtr property_rows = xmlDocument.SelectNodes(L"Properties/Property", row);
            MSXML2::IXMLDOMNodePtr property_row = NULL;
            while (NULL != (property_row = property_rows->nextNode()))
            {
                std::wstring name = xmlDocument.GetAttributeValue(L"name", property_row);
                std::wstring value = xmlDocument.GetAttributeValue(L"value", property_row);
                long escape = AppSecInc::StringUtils::stringToLong(xmlDocument.GetAttributeValue(L"escape", property_row, L"0"));
                properties[name] = escape == 1 ? AppSecInc::StringUtils::escape(value) : value;
            }
        }

        std::wstring data;
        bool utf8 = AppSecInc::File::ReadAndConvertToEnd(source, data);
        data = AppSecInc::Formatter::FormatTemplate(data, properties);

		std::string char_data;
		if (utf8) 
		{
			char_data = AppSecInc::StringUtils::wc2utf8(data);
			char_data.insert(0, std::string(reinterpret_cast<char *>(AppSecInc::File::utf8_bom)));
		}
		else
		{
			char_data = AppSecInc::StringUtils::wc2mb(data);
		}

        std::vector<char> binary_data;
        binary_data.assign(char_data.begin(), char_data.end());

        AppSecInc::File::FileWrite(target, binary_data);
    }

	MSI_EXCEPTION_HANDLER_EPILOG;
    return ERROR_SUCCESS;
}
//设置指定xpath的节点值
BOOL CXmlBase::SetNodeValue(LPCTSTR lpszValue, LPCTSTR lpszXPath 
	, MSXML2::IXMLDOMDocument2Ptr pDoc)
{
	if (pDoc == NULL || lpszXPath == NULL) return FALSE;
	MSXML2::IXMLDOMNodeListPtr pNodeList = pDoc->selectNodes(lpszXPath);
	long lCnt = pNodeList->Getlength();
	if (lCnt == 0) return FALSE;
	MSXML2::IXMLDOMNodePtr pNode = pNodeList->Getitem(0);
	return SetNodeValue(lpszValue, pNode);
}
Exemple #13
0
BOOL CIconImgList::PickUpGroups( MSXML2::IXMLDOMElementPtr& piGroup, int& nIndex)
{
    MSXML2::IXMLDOMNodeListPtr piGroupList;
    piGroupList = piGroup->GetchildNodes();

    MSXML2::IXMLDOMElementPtr piNode;
    MSXML2::IXMLDOMElementPtr piChild;

    int nParent = nIndex;

    _bstr_t cBstr;
    _variant_t cVariant;
    long lCount = piGroupList->Getlength();
    for( long lIndex = 0; lIndex < lCount; lIndex++)
    {
        piNode = piGroupList->Getitem( lIndex);
        if( _bstr_t( _T( "GROUP")) == piNode->GetbaseName())
        {
            cBstr = piNode->getAttribute( _bstr_t( _T( "TITLE")));
            cVariant = piNode->getAttribute( _bstr_t( _T( "ENABLE")));
            cVariant.ChangeType( VT_BOOL);

            m_astGroupData[ nIndex] = ( GROUPDATA*)malloc( sizeof( GROUPDATA) + ( sizeof( TCHAR) * ( cBstr.length() + 1)));

            m_astGroupData[ nIndex]->nParent = nParent;
            if( 1 <= nIndex)
            {
                if( FALSE == m_astGroupData[ nParent]->blEnable)
                {
                    cVariant.boolVal = VARIANT_FALSE;
                }
            }
            m_astGroupData[ nIndex]->blEnable = ( VARIANT_FALSE == cVariant.boolVal) ? FALSE : TRUE;
            lstrcpy( m_astGroupData[ nIndex]->szName, cBstr);

            nIndex++;

            PickUpGroups( piNode, nIndex);
        }
        else if( _bstr_t( _T( "ITEM")) == piNode->GetbaseName())
        {
            cVariant = piNode->getAttribute( _bstr_t( _T( "REF")));
            cVariant.ChangeType( VT_I4);
            for( int nIndex = 0; nIndex < m_nEnableCount; nIndex++)
            {
                if( cVariant.intVal == ( m_astIconStatus[ nIndex].nID + 1))
                {
                    m_astIconStatus[ nIndex].nParent = nParent;
                }
            }
        }
    }

    return TRUE;
}
// loads lists of Word styles from configuration XML file
BOOL CWordManager::loadStylesFromXML(LPCTSTR XMLFilePath)
{
	BOOL result = FALSE;	// return value
	CString FName;	// jmeno (cesta) ke konfig. souboru
	FName = XMLFilePath;

	MSXML2::IXMLDOMDocumentPtr pXMLDom;  // koren XML stromu
	MSXML2::IXMLDOMElementPtr pNode;	// korenovy element
	MSXML2::IXMLDOMNodeListPtr pChildren;  // seznam podelementu korenoveho elementu
	MSXML2::IXMLDOMNodeListPtr pChildrenItems;  // seznam podelementu elementu - vstupuje do funkce pro nacitani StringTable
	MSXML2::IXMLDOMElementPtr pChild;	//  podelement korenoveho elementu

	int i = 0;	// indexova promenna
	_variant_t  Atr_val;	// textova hodnota atributu
	HRESULT hr;
    
      //Vytvori COM objekt (resp. instanci objektu)
    hr = pXMLDom.CreateInstance(_T("Msxml2.DOMDocument"));
    if (FAILED(hr)) 
       return FALSE;
    pXMLDom->async = VARIANT_FALSE;
   
       //nacti DOM ze souboru
    if ( pXMLDom->load((LPCTSTR) FName) == VARIANT_TRUE)
	{
		pNode = pXMLDom->GetdocumentElement();
		if (pNode != NULL)
		{
			if (pNode->baseName == (_bstr_t) "word_styles") // spravny nazev korenoveho elementu
			{
				pChildren = pNode->childNodes;	// ziskani seznamu potomku
				pChild = NULL;
				while((pChild = pChildren->nextNode()) != NULL)  // zpracovavaji se potomci
				{
					pChildrenItems = pChild->childNodes;
					if (pChild->baseName == (_bstr_t) "templates")
						m_WordTemplates.loadItemsFromXML(pChildrenItems);

					else if (pChild->baseName == (_bstr_t) "paragraph_styles")
						m_WordParagraphStyles.loadItemsFromXML(pChildrenItems);

					else if (pChild->baseName == (_bstr_t) "character_styles")
						m_WordCharacterStyles.loadItemsFromXML(pChildrenItems);
					
				}
				result = TRUE;
			}
		}
	}

	pXMLDom.Release();

	return result;
}
Exemple #15
0
BOOL WXmlParse::readCalculateParams(WCalcaulateParam &calParam)
{
	MSXML2::IXMLDOMDocumentPtr doc;
	MSXML2::IXMLDOMElementPtr docRoot;  
	MSXML2::IXMLDOMElementPtr docElement;  
	MSXML2::IXMLDOMNodeListPtr elementNodes;  
	MSXML2::IXMLDOMNamedNodeMapPtr elementAttributes;
	MSXML2::IXMLDOMNodePtr xmlNode;  
	MSXML2::IXMLDOMNodePtr xmlSubNode; 
	MSXML2::IXMLDOMNodePtr xmlAttrNode; 
	doc.CreateInstance(__uuidof(DOMDocument30));  
	if (m_strFileName.IsEmpty())
	{
		return FALSE;
	}
	doc->load((_variant_t)m_strFileName);

	docRoot = doc->GetdocumentElement();//获得根节点;  
	docRoot->get_childNodes(&elementNodes);  
	LONG length, subLength, attrLength;
	elementNodes->get_length(&length);
	MSXML2::IXMLDOMNodeListPtr subElementNodes; 

	// 0 : 
	elementNodes->get_item(2, &xmlNode);
	xmlNode->get_childNodes(&subElementNodes);
	subElementNodes->get_length(&subLength);
	for (int j = 0; j < subLength;j++)
	{
		subElementNodes->get_item(j, &xmlSubNode);//获得某个属性
		xmlSubNode->get_attributes(&elementAttributes); 
		MSXML2::IXMLDOMNodePtr proNode = elementAttributes->getNamedItem("name");
		string proName = proNode->text;
		MSXML2::IXMLDOMNodeListPtr subAttrNodes; 
		xmlSubNode->get_childNodes(&subAttrNodes);
		subAttrNodes->get_length(&attrLength);
//		ASSERT(attrLength == 2);

		MSXML2::IXMLDOMNodePtr descNode;
		MSXML2::IXMLDOMNodePtr stateNode;
		subAttrNodes->get_item(0, &descNode);
		subAttrNodes->get_item(1, &stateNode);
		std::vector<string> vecParam;
		string descText = descNode->text;
		string stateText = stateNode->text;
		vecParam.push_back(proName);
		vecParam.push_back(descText);
		vecParam.push_back(stateText);

		calParam.addParam(vecParam);
	}

	return TRUE;
}
Exemple #16
0
/******************************************************************************
Function Name  :  GetData
Input(s)       :
Output         :  HRESULT
Functionality  :
Member of      :  CVerifyEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :
******************************************************************************/
HRESULT CVerifyEntity::GetCommonVerifyData(MSXML2::IXMLDOMNodePtr& pIDomNode, CVerifyData *verifyData)
{
	m_ouData = verifyData;
    _bstr_t bstrNodeName = def_STR_VERIFYMSG_NODE;
    CComVariant NodeValue;
    MSXML2::IXMLDOMNamedNodeMapPtr pDOMVerifyAtrributes;
    MSXML2::IXMLDOMNodePtr pIDOMChildNode;

    pDOMVerifyAtrributes = pIDomNode->Getattributes();
    //bstrNodeName = L"failure";
    bstrNodeName.Assign(SysAllocString(CT2W("failure")));
    pIDOMChildNode = pDOMVerifyAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);
    CString strTemp;
    strTemp = strCopyBSTRToCString(NodeValue);

	//m_ouData = new CVerifyData();
    if(strTemp == "SUCCESS")
    {
        m_ouData->m_eAttributeError = SUCCESS;
    }
    else if(strTemp == "WARNING")
    {
        m_ouData->m_eAttributeError = WARNING;
    }
    else if(strTemp == "ERRORS")
    {
        m_ouData->m_eAttributeError = ERRORS;
    }
    else
    {
        m_ouData->m_eAttributeError = FATAL;
    }
    MSXML2::IXMLDOMNodeListPtr pIDOMSendList;

    LONG lCount;
    //bstrNodeName = def_STR_VERIFYMSG_NODE;
    bstrNodeName.Assign(SysAllocString(CT2W(def_STR_VERIFYMSG_NODE)));
    pIDOMSendList = pIDomNode->selectNodes(bstrNodeName);
    pIDOMSendList->get_length(&lCount);

    for(int i = 0; i < lCount; i++)
    {
        CVerifySubEntity *odVerifySubEntity;
        MSXML2::IXMLDOMNodePtr pIXMLDOMVerifyMsgEntity;
        pIXMLDOMVerifyMsgEntity = pIDOMSendList->Getitem(i);
		//if(CVerifySubEntity::GetData(&odVerifySubEntity, pIXMLDOMVerifyMsgEntity) == S_OK)
		if(this->GetSubEntityData(&odVerifySubEntity, pIXMLDOMVerifyMsgEntity) == S_OK)
        {
            m_ouData->m_odVerifySubEntityList.push_back(odVerifySubEntity);
        }
    }
    return S_OK;
}
Exemple #17
0
	void readGeometry(dae_reader_t *reader, MSXML2::IXMLDOMDocument2Ptr xmlDoc)
	{
		MSXML2::IXMLDOMNodeListPtr nodeList;
		nodeList = xmlDoc->selectNodes("/r:COLLADA/r:library_geometries/r:geometry");
		int count = nodeList->length;

		for (int i = 0; i < count; i++)
		{
			MSXML2::IXMLDOMNodePtr node = nodeList->Getitem(i);
			readMesh(reader, node);
		}
	}
Exemple #18
0
size_t getChildrenCount(MSXML2::IXMLDOMNodePtr& node) {
  MSXML2::IXMLDOMNodeListPtr children;
  const HRESULT getChildNodesRes = node->get_childNodes(&children);
  if (FAILED(getChildNodesRes)) { 
    _com_raise_error(getChildNodesRes);
  }

  LONG chilrenCount = 0;
  const HRESULT getChildenCountRes = children->get_length(&chilrenCount);
  if (FAILED(getChildenCountRes)) {
    _com_raise_error(getChildenCountRes);
  }

  return chilrenCount;
}
Exemple #19
0
// 获取当前节点的指定位置的Element子节点
IBpXMLNode *CBpXMLNode::GetElementChildByIndex(int nIndex) const
{
	if (m_pDOMNode == NULL)
		return NULL;

	if (m_pDOMNode->GetnodeType() != MSXML2::NODE_ELEMENT)
		return NULL;

	MSXML2::IXMLDOMNodeListPtr pNodeList = m_pDOMNode->GetchildNodes();
	if (pNodeList == NULL)
		return NULL;

	long nListLen = 0;
	pNodeList->get_length(&nListLen);
	if (nIndex <= 0 || nIndex > nListLen)
		return NULL;

	MSXML2::IXMLDOMNodePtr pNode = NULL;
	int nRealIndex = 0;
	int nCount = 0;
	for (int i = 0; i < nListLen; i++) 
	{ 
		pNodeList->get_item(i, &pNode);
		if (pNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
		{
			nCount++;
			if (nCount == nIndex)
			{
				nRealIndex = i;	
				break;
			}
		}
	} 	

	if (nRealIndex < 0 || nRealIndex >= nListLen)
		return NULL;

	pNodeList->get_item(nRealIndex, &pNode);
	if (pNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
	{ 
		CBpXMLNode *pNodeCreated  = new CBpXMLNode();	
		pNodeCreated->m_pDOMNode = pNode;
		return (IBpXMLNode*)pNodeCreated;
	} 

	return NULL;
}
Exemple #20
0
//装入项目
void CUpdateBuilderDlg::OnBnClickedLoadItem()
{
	CFileDialog dlg(TRUE, _T("*.xml"), _T("update.xml"), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("XML File(*.xml)|*.xml||"));
	if (dlg.DoModal() == IDOK)
	{
		HRESULT hr = S_OK;
		MSXML2::IXMLDOMDocumentPtr	pXmlDoc;
		MSXML2::IXMLDOMNodeListPtr pNodeList;
		MSXML2::IXMLDOMElementPtr pElement;

		try
		{
			hr = pXmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
			if( FAILED( hr ) ) 
				_com_issue_error(hr);

			pXmlDoc->load(CComVariant(dlg.GetPathName()));
			
			pNodeList = pXmlDoc->selectNodes("/manifest/filelist/file");
			
			m_FileListCtrl.DeleteAllItems();
			LONG lItemCount = pNodeList->Getlength();
			int nItem; 

			for (LONG lIndex = 0; lIndex < lItemCount; lIndex++)
			{
				pElement = pNodeList->Getitem(lIndex);
				nItem = m_FileListCtrl.InsertItem(0, CString(pElement->getAttribute("filename")));
				m_FileListCtrl.SetItemText(nItem, 1, CString(pElement->getAttribute("filesize")));
				m_FileListCtrl.SetItemText(nItem, 2, CString(pElement->getAttribute("fileversion")));
				m_FileListCtrl.SetItemText(nItem, 3, CString(pElement->getAttribute("md5")));
				m_FileListCtrl.SetItemData(nItem, (ULONG)pElement->getAttribute("filesize"));
			}

			SetWindowText(dlg.GetPathName());
			GetDlgItem(IDC_UPDATE_ITEM)->EnableWindow(TRUE);
		}
		catch(_com_error& e)
		{
			CString strError;
			strError.Format(_T("Error code:%d\nError Message:%s\nError Description:%s"), 
				(int)e.WCode(), e.ErrorMessage(), (char*)e.Description());
			MessageBox(strError, _T("错误"),MB_OK|MB_ICONSTOP);
		}
	}
}
bstr_t CCMSDIntegrator::GetProperty(MSXML2::IXMLDOMNodePtr pNode,bstr_t PropName, bstr_t defaultVal, bstr_t NodeType)
{
	MSXML2::IXMLDOMNodeListPtr properties = pNode->selectNodes(NodeType);
	for(int j=0; j< properties->length; j++)
	{
		MSXML2::IXMLDOMNodePtr pProp = NULL;					
		properties->get_item(j, &pProp);
		MSXML2::IXMLDOMNodePtr pName = pProp->selectSingleNode(bstr_t(".//Name"));
		MSXML2::IXMLDOMNodePtr pValue = pProp->selectSingleNode(bstr_t(".//Value"));
		bstr_t propName =  (pName!=NULL) ? pName->Gettext() : L"None";
		if( propName == PropName)
		{
			return (pValue!=NULL) ? pValue->Gettext() : defaultVal;
		}
	}
	return defaultVal;
}
	void CXmlNodeWrapper::RemoveNodes(LPCTSTR searchStr)
	{
		if (!IsValid())
			return;
		MSXML2::IXMLDOMNodeListPtr nodeList = m_xmlnode->selectNodes(searchStr);
		for (int i = 0; i < nodeList->Getlength(); i++)
		{
			try
			{
				MSXML2::IXMLDOMNode* pNode = nodeList->Getitem(i).Detach();
				pNode->GetparentNode()->removeChild(pNode);
			}
			catch (_com_error er)
			{
				AfxMessageBox(er.ErrorMessage());
			}
		}
	}
Exemple #23
0
// 获取当前结点,指定名称的第index个Element子结点
IBpXMLNode *CBpXMLNode::GetElementChildByName(const wchar_t *szChildNodeName, int nIndex) const
{
	if (m_pDOMNode == NULL || nIndex <= 0)
		return NULL;

	int nCount = nIndex;
	if (m_pDOMNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
	{ 
		MSXML2::IXMLDOMNodeListPtr pNodeList = m_pDOMNode->GetchildNodes(); 
		if (pNodeList == NULL)
			return NULL;
		long nListLen = 0;
		pNodeList->get_length(&nListLen);; 
		int i = 0;
		MSXML2::IXMLDOMNodePtr pNode = NULL;
		for (;;)
		{ 
			pNodeList->get_item(i, &pNode); 
			if (pNode == NULL)
				break;

			if (pNode->GetnodeType() == MSXML2::NODE_ELEMENT) 
			{ 
				BSTR bstrText = NULL;
				m_pDOMNode->get_nodeName(&bstrText);
				CString strTempNodeName(bstrText);
				if (strTempNodeName.CompareNoCase(szChildNodeName))
				{
					nCount--;
					if(nCount == 0)
					{
						CBpXMLNode *pNodeCreated  = new CBpXMLNode();	
						pNodeCreated->m_pDOMNode = pNode;
						return (IBpXMLNode*)pNodeCreated;
					}
				}
			} 
			i++;
			if(i == nListLen)
				break;
		} 
	}
	return NULL;
}
Exemple #24
0
BOOL WXmlParse::readParam(std::vector<WParamDefine *> &outParams)
{
	MSXML2::IXMLDOMDocumentPtr doc;
	MSXML2::IXMLDOMElementPtr docRoot;  
	MSXML2::IXMLDOMElementPtr docElement;  
	MSXML2::IXMLDOMNodeListPtr elementNodes;  
	MSXML2::IXMLDOMNamedNodeMapPtr elementAttributes;
	MSXML2::IXMLDOMNodePtr xmlNode;  
	MSXML2::IXMLDOMNodePtr xmlSubNode; 
	MSXML2::IXMLDOMNodePtr xmlAttrNode; 
	doc.CreateInstance(__uuidof(DOMDocument30));  
	if (m_strFileName.IsEmpty())
	{
		return FALSE;
	}
	doc->load((_variant_t)m_strFileName);

	docRoot = doc->GetdocumentElement();//获得根节点;  
	docRoot->get_childNodes(&elementNodes);  
	LONG length, subLength, attrLength;
	elementNodes->get_length(&length);
	MSXML2::IXMLDOMNodeListPtr subElementNodes; 

	// 0 : 
	elementNodes->get_item(0, &xmlNode);
	xmlNode->get_childNodes(&subElementNodes);
	subElementNodes->get_length(&subLength);
	for (int j = 0; j < subLength;j++)
	{
		subElementNodes->get_item(j, &xmlSubNode);//获得某个属性
		xmlSubNode->get_attributes(&elementAttributes); 
		MSXML2::IXMLDOMNodePtr proNode = elementAttributes->getNamedItem("name");
		string proName = proNode->text;
		WParamDefine *paramTest = new WParamDefine(proName);
		MSXML2::IXMLDOMNodeListPtr subAttrNodes;  
		xmlSubNode->get_childNodes(&subAttrNodes);
		subAttrNodes->get_length(&attrLength);
		for (int k = 0;k < attrLength;k++)
		{
			subAttrNodes->get_item(k, &xmlAttrNode);
			string attrName = xmlAttrNode->nodeName;
			string attrText = xmlAttrNode->text;
			paramTest->addValue(attrName, attrText);
		}
		outParams.push_back(paramTest);
	}

	return TRUE;
}
////////////////////////////////////////////////////////////////////////////
// Function: Walk all the Elements in a loaded XML document.
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::WalkTree(CString& strSearchPattern)
{
	HRESULT hr = S_OK;

	if (strSearchPattern.IsEmpty())
	{
		MSXML2::IXMLDOMNodePtr pNode = m_pDoc;
		if (pNode == NULL)
			return E_FAIL;

		hr = WalkTree(0/*iLevel*/, pNode);
	}
	else
	{
		//j	("//video");
		//j	("//video[@id='crap1']");
		//j	("//video[@id='crap1']");

		// filter the nodes using the search pattern
		MSXML2::IXMLDOMNodeListPtr pNodeList = NULL;
		hr = m_pDoc->selectNodes(CComBSTR(strSearchPattern), &pNodeList);
		hr = CheckHR(hr, "in the search pattern");

		// get the length of the resulting node list
		if (pNodeList)
		{
			long lLength;
			hr = pNodeList->get_length(&lLength);
			hr = CheckHR(hr, "retrieving node list length");

			MSXML2::IXMLDOMNodePtr pNode = NULL;
			for (long i = 0; i < lLength; i++)
			{
				hr = pNodeList->get_item(i, &pNode);
				hr = WalkTree(0/*iLevel*/, pNode);
				if (hr != S_OK)
					return hr;
			}
		}
	}

	return hr;
}
/******************************************************************************
Function Name  :  nLoadTestCases
Input(s)       :  MSXML2::IXMLDOMNodePtr& pTSDOM
Output         :  INT
Functionality  :   
Member of      :  CTestSetupEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
Codetag        : CS004
******************************************************************************/
INT CTestSetupEntity::nLoadTestCases(MSXML2::IXMLDOMNodePtr& pTSDOM)
{
    LONG lCount;
    _bstr_t bstrNodeName(def_STR_TESTCASE_NODE);
    
    MSXML2::IXMLDOMNodeListPtr pDOMTCNodeList;
    MSXML2::IXMLDOMNodePtr pIXMLDOMTestCase;
    pDOMTCNodeList = pTSDOM->selectNodes(bstrNodeName);
    pDOMTCNodeList->get_length(&lCount);
    for(int i=0; i<lCount;i++)
    {
        CTestCaseEntity odTestCaseEntity;
        pIXMLDOMTestCase = pDOMTCNodeList->Getitem(i);
        odTestCaseEntity.GetData(pIXMLDOMTestCase);
        m_odTestCaseEntityList.AddTail(odTestCaseEntity);
    }
    return S_OK;

}
void Translator::Translate(IEnginePtr engine, InputStreamPtr readStream, SequenceFilePtr seqFile, TSError *error, char* errorMsg, long maxErrorMsgLengthInBytes)
{	
	GetParser()->LoadFile(readStream);
	std::string seqName = GetParser()->GetSequenceName();
	SequencePtr seq = engine->NewSequence();
	seq->Name = seqName.c_str();
	seqFile->InsertSequence(seq);
	m_totalSteps = 0;
	MSXML2::IXMLDOMNodeListPtr stepList = GetParser()->GetStepList();
	for ( int i = 0; i < stepList->length; ++i)
	{
		MSXML2::IXMLDOMNodePtr currentStep = stepList->Getitem(i);
		AddStep(engine, currentStep, GetParser()->GetStepProperties(currentStep), GetParser()->GetStepName(currentStep), seqFile, seqName);
	}
	//set the version property on the SequenceFile object
	std::string versionInfo;
	GetFileVersion(versionInfo, readStream, error, errorMsg, maxErrorMsgLengthInBytes);
	if( *error == TS_Err_NoError)
		seqFile->AsPropertyObjectFile()->Version = versionInfo.c_str();
}
//设置指定xpath的节点属性
BOOL CXmlBase::SetAttrValue(LPCTSTR lpszValue, LPCTSTR lpszAttrName, LPCTSTR lpszXPath 
	, MSXML2::IXMLDOMDocument2Ptr pDoc)
{
	MSXML2::IXMLDOMNodePtr pNode = NULL;
	MSXML2::IXMLDOMNodeListPtr pNodeList = NULL;
	long lCnt = 0;
	if (pDoc == NULL || lpszXPath == NULL) return FALSE;
	try
	{
		pNodeList = pDoc->selectNodes(lpszXPath);
		lCnt = pNodeList->Getlength();
		if (lCnt == 0) return FALSE;
		pNode = pNodeList->Getitem(0);
	}
	catch (_com_error e)
	{
		::MessageBox(NULL, e.ErrorMessage(), NULL, MB_OK|MB_ICONERROR);
		return FALSE;
	}
	return SetAttrValue(lpszValue, lpszAttrName, pNode);
}
Exemple #29
0
long CIconImgList::GetGroupCount( MSXML2::IXMLDOMElementPtr piGroups)
{
    long lCount = 0;

    MSXML2::IXMLDOMNodeListPtr piGroupsList;
    piGroupsList = piGroups->selectNodes( _bstr_t( _T( "GROUP")));
    if( NULL != piGroupsList)
    {
        long lChildCount = piGroupsList->Getlength();

        lCount = lChildCount;

        MSXML2::IXMLDOMElementPtr piGroupChild;
        for( long lIndex = 0; lIndex < lChildCount; lIndex++)
        {
            piGroupChild = piGroupsList->Getitem( lIndex);
            lCount += GetGroupCount( piGroupChild);
        }
    }
    return lCount;
}
Exemple #30
-3
CA_API UINT __stdcall LocalGroupMembers_Deferred(MSIHANDLE hInstall)
{
	MSI_EXCEPTION_HANDLER_PROLOG;
    MsiInstall msiInstall(hInstall);

    AppSecInc::Xml::XmlDocument xmlDocument;
    xmlDocument.LoadXml(msiInstall.GetActionData());

    MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"/LocalGroupMembers/LocalGroupMember");
    MSXML2::IXMLDOMNodePtr row = NULL;
    while (NULL != (row = rows->nextNode()))
    {
        std::wstring id = xmlDocument.GetAttributeValue(L"id", row);
        std::wstring username = xmlDocument.GetNodeValue(L"Username", row);
        std::wstring groupname = xmlDocument.GetNodeValue(L"Group", row, L"");
        bool add_member = xmlDocument.GetAttributeBoolValue(L"add", row);
        bool remove_member = xmlDocument.GetAttributeBoolValue(L"remove", row);
        bool check = xmlDocument.GetAttributeBoolValue(L"check", row);

        if (remove_member && (! check || AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
        {
            msiInstall.LogInfo(_T(__FUNCTION__), L"Removing \"" + username + L"\" from \"" + groupname + L"\"");
            AppSecInc::LSA::LocalGroup::DeleteMember(groupname, username);
        }

        if (add_member && (! check || ! AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
        {
            msiInstall.LogInfo(_T(__FUNCTION__), L"Adding \"" + username + L"\" to \"" + groupname + L"\"");
            AppSecInc::LSA::LocalGroup::AddMember(groupname, username);
        }
    }

	MSI_EXCEPTION_HANDLER_EPILOG;
    return ERROR_SUCCESS;
}