////////////////////////////////////////////////////////////////////////////
// Helper function: Walk all the Elements at a particular node
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::WalkTree(int iLevel, MSXML2::IXMLDOMNode* pNode)
{
	HRESULT hr = S_OK;

	CComBSTR bstrNodeName;
	pNode->get_nodeName(&bstrNodeName);

	CComVariant vNodeValue;
	pNode->get_nodeValue(&vNodeValue);
	vNodeValue.ChangeType(VT_BSTR);
	CString strValueString = V_BSTR(&vNodeValue);

	if (m_pCallbackFunction)
		m_pCallbackFunction(iLevel, CString(bstrNodeName), (LPCSTR)NULL, strValueString, m_pCallbackParam);

	MSXML2::IXMLDOMNamedNodeMapPtr pAttributes = NULL;
	if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL))
	{
		MSXML2::IXMLDOMNodePtr pAttribute = NULL;
		pAttributes->nextNode(&pAttribute);
		bool bRetVal = true;
		while (pAttribute)
		{
			CComBSTR bstrAttribName;
			pAttribute->get_nodeName(&bstrAttribName);

			CComVariant vNodeValue;
			pAttribute->get_nodeValue(&vNodeValue);
			vNodeValue.ChangeType(VT_BSTR);
			CString strValueString = V_BSTR(&vNodeValue);

			if (m_pCallbackFunction)
				bRetVal = m_pCallbackFunction(iLevel+1, CString(bstrNodeName), CString(bstrAttribName), strValueString, m_pCallbackParam);

			if (!bRetVal)
			{
				// set complete error message with node name and all attribute values
				m_strErrorNode = bstrNodeName;
				return S_FALSE;
			}

			pAttributes->nextNode(&pAttribute);
		}
	}

	MSXML2::IXMLDOMNodePtr pChild = NULL;
	pNode->get_firstChild(&pChild);
	while (pChild)
	{
		if (WalkTree(iLevel+1, pChild) != S_OK)
			return S_FALSE;

		MSXML2::IXMLDOMNode* pNext = NULL;
		pChild->get_nextSibling(&pNext);
		pChild = pNext;
	}

	return S_OK;
}
int CXmlBase::GetAttrsOfNode(map<CString, CComBSTR>& mapAttrs, MSXML2::IXMLDOMNodePtr pNode)
{
	MSXML2::IXMLDOMNamedNodeMapPtr pAttrs;
	MSXML2::IXMLDOMNodePtr pAttr;
	HRESULT hr;
	CComBSTR bstrText;
	CString str;
	long lAttrCount = 0;

	mapAttrs.clear();
	
    if (NULL == pNode)
	{
		//WRITELOG("END, pNode为空");
		return 0;
	}

	pAttrs = pNode->Getattributes();
	if (pAttrs == NULL)
	{
		//WRITELOG("END, 取得节点属性集合失败");
		return 0;
	}

	lAttrCount = pAttrs->Getlength();
	for (int i=0; i<lAttrCount; i++)
	{
		pAttr = pAttrs->Getitem(i);
		if (pAttr == NULL)
		{
			//WRITELOG("取得第[%d]个属性为空", i); 
			continue;
		}

		hr = pAttr->get_nodeName(&bstrText);
		if (FAILED(hr))
		{
			//WRITELOG("取得第[%d]个属性名为空", i); 
			continue;
		}
		if (!ConvertBSTR2CString(str, bstrText.m_str))
		{
			//WRITELOG("转换第[%d]个属性名 失败", i); 
			continue;
		}
		hr = pAttr->get_text(&bstrText);
		if (FAILED(hr))
		{
			//WRITELOG("取得第[%d]个属性值 失败,属性[%s]", i, str); 
			continue;
		}
		mapAttrs.insert(make_pair(str, bstrText));
	}
	
	return (int)mapAttrs.size();
}
void XmlParser::_parseNodeGetAttributes(MSXML2::IXMLDOMNode *pIDOMNode, XmlNode& node)
{
	MSXML2::IXMLDOMNamedNodeMapPtr attributes = pIDOMNode->attributes;
	BSTR attrName;

	for (int i = 0; i < attributes->Getlength(); i++)
	{
		MSXML2::IXMLDOMNodePtr atrr = attributes->Getitem(i);

		atrr->get_nodeName(&attrName);
		_variant_t val = atrr->GetnodeValue();
		
		wstring name(attrName);
		BSTR b = val.bstrVal;
		wstring value(b);

		XmlAttribute attribute(name, value);
		node.AddAttribute(attribute);
	}
}
Exemple #4
0
CXmlNodePtr CXmlNodes::GetItem( LPCTSTR lpszName )
{
	ASSERT( lpszName != NULL );
	
	HRESULT hr = S_OK;
	CString strName;
	BSTR bstr = NULL;
	MSXML2::IXMLDOMNodePtr pItem = NULL;

	CXmlNodePtr pNode ( new CXmlNode() );

	for( int i = 0; i < m_pNodeList->length; i++)
	{
		pItem = m_pNodeList->item[i];

		hr = pItem->get_nodeName(&bstr);
		ASSERT( SUCCEEDED(hr) );

		strName = (LPCTSTR)_bstr_t( bstr, true);
		if( bstr != NULL )
		{
			SysFreeString(bstr);
			bstr = NULL;
		}

		// 
		if( strName.Compare(lpszName) == 0 )
		{
			pNode->m_pNode = pItem;
			SAFE_RELEASE(pItem);
			return pNode;
		}

		SAFE_RELEASE(pItem);
	}

	return pNode;
}
/******************************************************************************
Function Name  :  GetData
Input(s)       :  MSXML2::IXMLDOMNodePtr& pIDomNode
Output         :  HRESULT
Functionality  :  Fills the datastructure from the XML node 
Member of      :  CTestCaseEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
******************************************************************************/
HRESULT CTestCaseEntity::GetData(MSXML2::IXMLDOMNodePtr& pIDomNode)
{
//Getting Attributes
    _bstr_t bstrNodeName;
    CComVariant NodeValue;	
    MSXML2::IXMLDOMNamedNodeMapPtr pDOMTCAtrributes;
    pDOMTCAtrributes = pIDomNode->Getattributes();
    MSXML2::IXMLDOMNodePtr pIDOMChildNode;

    //bstrNodeName = L"identifier";
	bstrNodeName.Assign(SysAllocString(CT2W("identifier")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);		
	m_ouData.m_omID = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();
    
    //bstrNodeName = L"title";
	bstrNodeName.Assign(SysAllocString(CT2W("title")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);		
	m_ouData.m_omTitle = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();

    //bstrNodeName = L"exp_handler";
	bstrNodeName.Assign(SysAllocString(CT2W("exp_handler")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);
	CString strTemp;	
	strTemp = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();
    
    if(strTemp == "CONTINUE")
    {
        m_ouData.m_eExcpAction = CONTINUE;
    }
    else
    {
        m_ouData.m_eExcpAction = EXIT;
    }

//Getting Testcases
    MSXML2::IXMLDOMNodeListPtr pDOMChildList = pIDomNode->GetchildNodes();
    LONG lCount;
    pDOMChildList->get_length(&lCount);
    CComBSTR NodeName;
    for(int i = 0;i < lCount; i++)
    {
        pIDOMChildNode = pDOMChildList->Getitem(i);
        pIDOMChildNode->get_nodeName(&NodeName);        
		
        CBaseEntityTA *odpBaseEntity = NULL;
		if(NodeName == def_STR_SEND_NODE)
        {
            odpBaseEntity = new CSendEntity();
        }
        else if(NodeName == def_STR_VERIFY_NODE)
        {
            odpBaseEntity = new CVerifyEntity();
        }
        else if(NodeName == def_STR_WAIT_NODE)
        {
            odpBaseEntity = new CWaitEntity();
        }
        else if(NodeName == def_STR_REPLAY_NODE)
        {
            odpBaseEntity = new CReplayEntity();
        }
        else if(NodeName == def_STR_VERIFYRES_NODE)
        {
            odpBaseEntity = new CVerifyResponse();
        }
        if(odpBaseEntity == NULL)
        {
            //TODO::return a correct value
            return -1;
        }
        odpBaseEntity->GetData(pIDOMChildNode);
        m_ouData.m_odTAEntityList.AddTail(odpBaseEntity);
        //pIDOMChildNode->Release();
    }
    return S_OK;
}
Exemple #6
0
//////////////////////////////////////////////////////////////////////////
//简要描述 : 设置扩展属性配置文件
//输入参数 :
//返 回 值 :
//
//
//修改日志 :
//////////////////////////////////////////////////////////////////////////
STDMETHODIMP CDwgWriter::put_XDataXMLConfigFile(BSTR sXMLFile)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    if (sXMLFile == NULL) return S_OK;

    CString sXml = sXMLFile;
    if (sXml.IsEmpty()) return S_OK;

    m_XDataCfgs.RemoveAll();

    try
    {
        CXMLFile xmlfile;
        xmlfile.load(sXml);
        MSXML2::IXMLDOMNodePtr pNode;
        MSXML2::IXMLDOMNodePtr pExtAttrNode = NULL;
        xmlfile.GetNode("LAYERS", pNode);
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        pNode = pNode->GetfirstChild();
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        CComBSTR bsNodeName;
        CComBSTR bsExtAttrs;
        CString sLayerName;
        CString sRegAppName;
        CString sExtAttrs;
        while (pNode != NULL)
        {
            //得到图层名
            pNode->get_nodeName(&bsNodeName);
            sLayerName = bsNodeName;

            //去掉前面的_前缀,解决数字开头的节点问题
            CString sSign = "";
            sSign = sLayerName.Mid(0, 1);
            if (sSign.CompareNoCase("_") == 0)
            {
                sLayerName = sLayerName.Mid(1);
            }

            XDataAttrLists* pExtAttrs = new XDataAttrLists();
            //得到图层下的注册应用名
            if (pNode->hasChildNodes())
            {
                pExtAttrNode = pNode->GetfirstChild();
                while (pExtAttrNode != NULL)
                {
                    pExtAttrNode->get_nodeName(&bsNodeName);
                    sRegAppName = bsNodeName;

                    //去掉前面的_前缀,解决数字开头的节点问题
                    sSign = sRegAppName.Mid(0, 1);
                    if (sSign.CompareNoCase("_") == 0)
                    {
                        sRegAppName = sRegAppName.Mid(1);
                    }

                    pExtAttrNode->get_text(&bsExtAttrs);
                    sExtAttrs = bsExtAttrs;
                    CStringList* pAttrLst = new CStringList();
                    //解析注册应用名下的属性字段名称
                    CString sAttr;
                    int iPos  = sExtAttrs.Find(',');
                    while (iPos > 0)
                    {
                        sAttr = sExtAttrs.Mid(0, iPos);
                        sExtAttrs = sExtAttrs.Mid(iPos + 1);
                        if (!sAttr.IsEmpty())
                        {
                            pAttrLst->AddTail(sAttr);
                        }
                        iPos  = sExtAttrs.Find(',');
                    }
                    if (iPos == -1)
                    {
                        if (!sExtAttrs.IsEmpty())
                        {
                            pAttrLst->AddTail(sExtAttrs);
                        }
                    }
                    pExtAttrs->SetAt(sRegAppName, pAttrLst);
                    //得到下一个注册应用名的配置
                    pExtAttrNode = pExtAttrNode->GetnextSibling();
                }
            }

            m_XDataCfgs.SetAt(sLayerName, pExtAttrs);
            //得到下一个图层的扩展属性的配置
            pNode = pNode->GetnextSibling();
        }
    }
    catch (...)
    {
		m_dwgWriter.WriteLog("解析XML文件出错,请检查。");
        return S_FALSE;
    }

    return S_OK;
}