Ejemplo n.º 1
0
//-------------------------------------------------------------------------
// Function Name    :Base64Decode
// Parameter(s)     :LPCTSTR pszIn	Base64编码
//					:LPBYTE pBuf	缓冲区首地址
//					:ULONG &ulSize	缓冲区大小
// Return           :BOOL
// Memo             :将Base64编码解码为二进制形式 
//					注意!此函数的缓冲区需要在函数调用完后删除
//-------------------------------------------------------------------------
BOOL CXml::Base64Decode(LPCTSTR pszIn, LPBYTE& pBuf, LONG& lSize)
{
	ASSERT(m_pDoc != NULL);
	
	try
	{
		MSXML2::IXMLDOMElementPtr pElement = NULL;
		pElement = m_pDoc->createElement(_bstr_t(_T("Base64")));
		ASSERT(pElement != NULL);

		HRESULT hr = S_OK;
		hr = pElement->put_dataType(_bstr_t(_T("bin.base64")));
		ASSERT(SUCCEEDED(hr));

		hr = pElement->put_text(CComBSTR(pszIn));
		ASSERT(SUCCEEDED(hr));

        hr = SafeArrayGetUBound(pElement->nodeTypedValue.parray, 1, &lSize);
		ASSERT(SUCCEEDED(hr));
		lSize ++;

		pBuf = new BYTE[lSize];
		memset(pBuf, 0, lSize);

		memcpy(pBuf, LPVOID(pElement->nodeTypedValue.parray->pvData), lSize);	

		RELEASE_PTR(pElement);
	}
	catch (_com_error e)
	{
		TRACE(_T("CXml::Base64Decode 发生异常:%s\n"), e.ErrorMessage());
		ASSERT(FALSE);
		return FALSE;
	}
	
	return TRUE;
}
Ejemplo n.º 2
0
BOOL WXmlParse::writeParam(const std::vector<WParamDefine *> &params)
{
	/*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;
	}

	docRoot = doc->createElement("ModuleName");
	//docRoot->setAttribute(_T("name"), (_variant_t) _T("CategoryProduct"));

	MSXML2::IXMLDOMElementPtr inputElement = doc->createElement("InputParam");
	docRoot->appendChild(inputElement);
	for (int i = 0;i < params.size();i++)
	{

	}*/

	MSXML2::IXMLDOMDocumentPtr pDoc = NULL; 
	MSXML2::IXMLDOMElementPtr xmlRoot = NULL; 
	MSXML2::IXMLDOMElementPtr xmlInput = NULL; 
	MSXML2::IXMLDOMProcessingInstructionPtr pPI = NULL; 
	//创建DOMDocument对象 
	pDoc.CreateInstance(__uuidof(DOMDocument30)); 
	pPI = pDoc->createProcessingInstruction("xml","version='1.0' encoding='gb2312'"); 
	_variant_t vNullVal; 
	vNullVal.vt = VT_NULL; 
	pDoc->insertBefore(pPI, vNullVal);
	//创建元素并添加到文档中 
	xmlRoot = pDoc->createElement((_bstr_t)"ModuleName"); 
	//设置属性 
	
	pDoc->appendChild(xmlRoot);
	appendTextNode(pDoc,xmlRoot,1);

	xmlInput = pDoc->createElement((_bstr_t)"InputParams");
	xmlInput->setAttribute(_T("name"), (_variant_t) _T("CategoryProduct"));
	xmlRoot->appendChild(xmlInput);
	appendTextNode(pDoc, xmlInput, 2);

	for (int i = 0;i < params.size();i++)
	{
		MSXML2::IXMLDOMElementPtr pProperty = pDoc->createElement((_bstr_t)"Property");
		pProperty->setAttribute((_bstr_t)"name", (_bstr_t)(params[i]->m_name.c_str()));
		xmlInput->appendChild(pProperty);
		appendTextNode(pDoc, pProperty, 3);
		WExtraMap::iterator it = params[i]->m_extraParams.begin();
		while (it != params[i]->m_extraParams.end())
		{
			MSXML2::IXMLDOMElementPtr pText = pDoc->createElement((_bstr_t)it->first.c_str());
			pText->put_text((_bstr_t)it->second.c_str());
			pProperty->appendChild(pText);
			appendTextNode(pDoc, pProperty, 3);
			it++;
		}
	}

	//添加“author”元素 
// 	MSXML2::IXMLDOMElementPtr pNode; 
// 	pNode=pDoc->createElement((_bstr_t)"Bank"); 
// 	xmlRoot->appendChild(pNode);
// 
// 	appendTextNode(pDoc,pNode,2);
// 
// 	MSXML2::IXMLDOMElementPtr pNode2; 
// 	pNode2=pDoc->createElement((_bstr_t)"Head"); 
// 	pNode->appendChild(pNode2);
// 
// 	appendTextNode(pDoc,pNode2,3);
// 
// 	MSXML2::IXMLDOMElementPtr pNode3; 
// 	pNode3=pDoc->createElement((_bstr_t)"PBCCode"); 
// 	pNode3->Puttext("局势"); 
// 	pNode2->appendChild(pNode3);
// 
// 	appendTextNode(pDoc,pNode2,2);
// 
// 	pNode3=pDoc->createElement((_bstr_t)"Code"); 
// 	pNode3->Puttext("局势"); 
// 	pNode2->appendChild(pNode3);
// 
// 	///////////////////////////////////////////////////
// 	appendTextNode(pDoc,pNode2,2);
// 	//////////////////////////////////////////////////////
// 	appendTextNode(pDoc,pNode,2);
// 
// 	pNode2=pDoc->createElement((_bstr_t)"Table1"); 
// 	pNode->appendChild(pNode2);
// 
// 	appendTextNode(pDoc,pNode2,3);
// 
// 	pNode3=pDoc->createElement((_bstr_t)"PBCCode"); 
// 	pNode3->Puttext("局势"); 
// 	pNode2->appendChild(pNode3);
// 
// 	appendTextNode(pDoc,pNode2,2);
// 
// 	pNode3=pDoc->createElement((_bstr_t)"Code"); 
// 	pNode3->Puttext("局势"); 
// 	pNode2->appendChild(pNode3);
// 
// 	///////////////////////////////////////////////////
// 	appendTextNode(pDoc,pNode2,2);
// 	//////////////////////////////////////////////////////
// 
// 	appendTextNode(pDoc,pNode,1);
// 	appendTextNode(pDoc,xmlRoot,0);
// 
 	pDoc->save("D:\\he.xml");

	return TRUE;
}