예제 #1
0
//--------------------------------------------------------------------------------------
HRESULT CRatingsDB::GetDescriptorName( WCHAR* strRatingSystemGUID, WCHAR* strDescriptorGUID, WCHAR* strDest, int cchDest )
{
    wcscpy_s( strDest, cchDest, strDescriptorGUID );

    WCHAR strRatingSystemGUIDUpper[512];
    wcscpy_s( strRatingSystemGUIDUpper, 512, strRatingSystemGUID );
    _wcsupr_s( strRatingSystemGUIDUpper );

    WCHAR strDescriptorGUIDUpper[512];
    wcscpy_s( strDescriptorGUIDUpper, 512, strDescriptorGUID );
    _wcsupr_s( strDescriptorGUIDUpper );

    HRESULT hr;
    IXMLDOMNode* pRatingSystemNode = nullptr;
    WCHAR str[512];
    swprintf_s( str, 512, L"//Ratings/RatingSystem[@ID='%s']", strRatingSystemGUIDUpper );

    hr = m_pRootNode->selectSingleNode( str, &pRatingSystemNode );
    if( SUCCEEDED(hr) && pRatingSystemNode )
    {
        IXMLDOMNode* pRatingIDNode = nullptr;
        swprintf_s( str, 512, L"Descriptor[@ID='%s']", strDescriptorGUIDUpper );
        hr = pRatingSystemNode->selectSingleNode( str, &pRatingIDNode );
        if( SUCCEEDED(hr) && pRatingIDNode )
        {
            hr = GetAttribFromNode( pRatingIDNode, L"Text", strDest, cchDest );
            SAFE_RELEASE( pRatingIDNode );
        }
        SAFE_RELEASE( pRatingSystemNode );
    }

    return hr;
}
예제 #2
0
/*
	 Function name		: CXML::GetNode
	 Description	    : This is a helper function which, gives the pointer to node.
						: searching for node can be started either from the current node
						: or it may be started from the Root Node depending on the value of 
						: bCurrentNodeAsBase.
	 Return type		: bool 
	 Argument			: CString csPathToNode
	 Argument			: LPCTSTR lpszAttribute
	 Argument			: LPCTSTR lpszValue
	 Argument			: bool bCurrentNodeAsBase
	 Tested				: Ok
*/	
bool CXML::GetNode(IXMLDOMNode ** pNode,CString &rcsPathToNode,LPCTSTR lpszAttribute,LPCTSTR lpszValue,bool bCurrentNodeAsBase )
{
	IXMLDOMNode * pBaseNode  = NULL;
	CString csPath("");

	if(bCurrentNodeAsBase)
	{
		if(!m_pICurrentNode) 
			return false;

		pBaseNode  = m_pICurrentNode;
		if(lpszAttribute)
			csPath.Format("./%s[@%s = \"%s\"]",rcsPathToNode,lpszAttribute,lpszValue);
		else
			csPath.Format("./%s",rcsPathToNode);
	}
	else
	{
		if(!m_pIRootNode) 
			return false;

		pBaseNode   = m_pIRootNode;
		if(lpszAttribute)
			csPath.Format("/%s[@%s = \"%s\"]",rcsPathToNode,lpszAttribute,lpszValue);
		else
			csPath.Format("/%s",rcsPathToNode);
	} 
	
	pBaseNode->AddRef();		 

	BSTR bsPathToNode = csPath.AllocSysString();

	m_hr =	pBaseNode->selectSingleNode(bsPathToNode,pNode);

	SysFreeString(bsPathToNode);
	pBaseNode ->Release();
		
	if (!SUCCEEDED(m_hr) || !(*pNode))
		return false;

return true;
}
예제 #3
0
/*
	Function name	: CXML::GoToNode
	Description	    : Moves to the node having the specified text
	Return type		: bool 
	Argument        : CString csPathToNode
	Argument        : CString csNodeText
	Argument        : bool bCurrentNodeAsBase
	Tested			: Not working
*/
bool CXML::GoToNodeEx(CString csPathToNode,CString csNodeText,bool bCurrentNodeAsBase)
{
	CString csPath;
	IXMLDOMNode *pBaseNode = NULL;
	
	if(bCurrentNodeAsBase)
	{
		if(!m_pICurrentNode) return false;

		pBaseNode = m_pICurrentNode;
		pBaseNode->AddRef();
		csPath.Format("./%s[.= \"%s\"]",csPathToNode,csNodeText);
	}
	else
	{
		if(!m_pIRootNode) return false;
		pBaseNode = m_pIRootNode;
		pBaseNode->AddRef();
		csPath.Format("/%s[.= \"%s\"]",csPathToNode,csNodeText);
	}

	BSTR bstrPath = csPath.AllocSysString();

	IXMLDOMNode * pNode = NULL;
	m_hr = pBaseNode->selectSingleNode(bstrPath,&pNode);
	pBaseNode->Release();
	SysFreeString(bstrPath);

	if(!SUCCEEDED(m_hr) || !pNode)
		return false;


	if(m_pICurrentNode)
	{
		m_pICurrentNode->Release();
		m_pICurrentNode = NULL;
	}
	m_pICurrentNode = pNode;
	m_pICurrentNode->AddRef();
	pNode->Release();	
	return true;
}
예제 #4
0
bool CXML::GoToNodeEx(CString csPathToNode,char **ppTagNames,char** ppAttributes,char **ppValues,int nTagCount,bool bCurrentNodeAsBase)
{
	CString csPath;
	IXMLDOMNode *pBaseNode = NULL;
	
	if(!ppTagNames && !ppAttributes && !ppValues)
		return false;

	if(bCurrentNodeAsBase)
	{
		if(!m_pICurrentNode) return false;

		pBaseNode = m_pICurrentNode;
		pBaseNode->AddRef();
		csPath = ".";
	}
	else
	{
		if(!m_pIRootNode) return false;

		pBaseNode = m_pIRootNode;
		pBaseNode->AddRef();
		csPath = "";
	}
	
	int nNextIndex = 0,nLastIndex = 0;

	
	for(int i=0;i<nTagCount;++i)
	{
		if(nNextIndex > csPathToNode.GetLength())
			break;
		nLastIndex = csPathToNode.Find(ppTagNames[i],nNextIndex);
		if(nLastIndex<0)
			return false;
		if(nLastIndex>nNextIndex)
		{
			CString csTemp = csPathToNode.Mid(nNextIndex,(nLastIndex-nNextIndex)-1);
			csPath +="/";
			csPath += csTemp;
		}
		nNextIndex = nLastIndex + strlen(ppTagNames[i])+1;
		CString csTag;
		csTag.Format("/%s[@%s = \"%s\"]",ppTagNames[i],ppAttributes[i],ppValues[i]);
		csPath += csTag;
	}
	

	BSTR bstrPath = csPath.AllocSysString();

	IXMLDOMNode * pNode = NULL;
	m_hr = pBaseNode->selectSingleNode(bstrPath,&pNode);
	pBaseNode->Release();
	SysFreeString(bstrPath);

	if(!SUCCEEDED(m_hr) || !pNode)
		return false;
	if(m_pICurrentNode)
	{
		m_pICurrentNode->Release();
		m_pICurrentNode = NULL;
	}
	m_pICurrentNode = pNode;
	m_pICurrentNode->AddRef();
	pNode->Release();	
	return true;

}
예제 #5
0
HRESULT CKADmerge::SetValueByPattern(string sElementPattern,
                                     string sAttributePattern,
                                     string sValue,
                                     string sLogFile)
{
    HRESULT hRes = 0;

    if(sLogFile != "")
    {
        // open log file
        OpenLog(sLogFile, sDescription + " " + m_sFileName);
    }

    IXMLDOMNode * pElemNode = NULL;
    IXMLDOMNode * pAttrNode = NULL;
    _bstr_t bElementPattern(sElementPattern.c_str());

    try
	{
        // get element node
        hRes = m_pXMLKad->selectSingleNode(bElementPattern, &pElemNode);
        if(hRes == S_FALSE)
        {
            hRes = S_FALSE;
            throw string("node access error");
        }

        if(sAttributePattern.length())
        {
            // get attribute node by pattern string
            _bstr_t bAttributePattern(sAttributePattern.c_str());

            hRes = pElemNode->selectSingleNode(bAttributePattern, &pAttrNode);
            if(hRes == S_FALSE)
            {
                throw string("node access error");
            }

            // set attribute value
            _bstr_t bAttlanguage(sValue.c_str());
            VARIANT vAttlanguage;
            vAttlanguage.vt = VT_BSTR;
            V_BSTR(&vAttlanguage) = bAttlanguage.copy();

            hRes = pAttrNode->put_nodeValue(vAttlanguage);
            VariantClear(&vAttlanguage);
        }
        else
        {
            // set element value
            hRes = SetValue(pElemNode, sValue);
        }


        if(hRes == S_OK)
        {
            SaveXMLFile(m_sFileName, m_pXMLKad);
            // log changes
            Log("SetValueByPattern - Set value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue);
        }

        //delete pwAttlanguage;
        if(FAILED(hRes))
        {
            hRes = S_FALSE;
            throw string("value error");
        }
	}
	catch(string str)
	{
        hRes = S_FALSE;
        // log changes
        Log("SetValueByPattern - Set value failed: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue);
        Log("ERROR: " + str);
	}

	if(pElemNode != NULL)
		pElemNode->Release();
	if(pAttrNode != NULL)
		pAttrNode->Release();

    // close log file
    CloseLog();

    return hRes;
}
예제 #6
0
HRESULT CKADmerge::GetValueByPattern(string sElementPattern,
                                     string sAttributePattern,
                                     string & sValue,
                                     string sLogFile)
{
    HRESULT hRes = 0;

    if(sLogFile != "")
    {
        // open log file
        OpenLog(sLogFile, sDescription + " " + m_sFileName);
    }

    IXMLDOMNode * pElemNode = NULL;
    IXMLDOMNode * pAttrNode = NULL;
    _bstr_t bElementPattern(sElementPattern.c_str());

    try
	{
        // get element node by pattern string

        hRes = m_pXMLKad->selectSingleNode(bElementPattern, &pElemNode);
        if(hRes == S_FALSE)
        {
            throw string("node access error");
        }

        if(sAttributePattern.length())
        {
            // get attribute node by pattern string
            _bstr_t bAttributePattern(sAttributePattern.c_str());

            hRes = pElemNode->selectSingleNode(bAttributePattern, &pAttrNode);
            if(hRes == S_FALSE)
            {
                throw string("node access error");
            }
            // get attribute value
            sValue = GetValue(pAttrNode);
        }
        else
        {
            // get element value
            sValue = GetValue(pElemNode);
        }
        hRes = S_OK;

        // log changes
        Log("GetValueByPattern - Get value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' is: " + sValue);
	}
	catch(string str)
	{
        sValue = "";
        hRes = S_FALSE;
        // log changes
        Log("GetValueByPattern - Get value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern);
        Log("ERROR: " + str);
	}

	if(pElemNode != NULL)
		pElemNode->Release();
	if(pAttrNode != NULL)
		pAttrNode->Release();

    // close log file
    CloseLog();

    return hRes;
}