Ejemplo n.º 1
0
void CXMLDlg::OnLoad() 
{
	CWaitCursor Wait;

	UpdateData();

	HRESULT hr = S_OK;

	HTREEITEM hFirstItem = m_treeOutput.GetChildItem(TVI_ROOT);
	if (hFirstItem)
		m_treeOutput.Expand(hFirstItem, TVE_COLLAPSE);
	m_treeOutput.DeleteAllItems();

	CoInitialize(NULL);

	// Create an empty XML document
	CXMLDocument* pXMLDoc = new CXMLDocument;
	hr = pXMLDoc->RegisterCallback(&MyXMLCallback, (LPARAM)this);

	if (m_strFileName.IsEmpty())
	{
		hr = pXMLDoc->Build(); // load a document from in-memory string.
	}
	else
	{
		if (m_bStream)
			hr = pXMLDoc->LoadStream(m_strFileName);
		else
			hr = pXMLDoc->Load(m_strFileName, !!m_bAsync);
	}

	// Now walk the loaded XML document dumping the name-value pairs
	pXMLDoc->WalkTree(CString(""));

//j	// Test persistence of encoded XML doc in memory
//j	PBYTE pData = NULL;
//j	ULONG ulLen;
//j	hr = pXMLDoc->PersistToMemory(&pData, &ulLen);
//j	hr = pXMLDoc->LoadFromMemory(pData, ulLen);
//j	delete pData;
	
	delete pXMLDoc;
	CoUninitialize();
}
Ejemplo n.º 2
0
bool CFYSPrintDoc::SendXmlDoc(CString strURL)
{
	CComPtr<IWebBrowser2> pBrowser;
	HRESULT hr = pBrowser.CoCreateInstance(_bstr_t("InternetExplorer.Application"));
	if (hr != S_OK)
	{
		SetError("Failed to start IE!.");
		return false;
	}
	
	CString strSendFile = m_strFYSTempPath + FORYOURSOUL_TXT;
	CHTTPClient *pHttpClient = new CHTTPClient(pBrowser);
	pHttpClient->AddPostArguments("File1", strSendFile, true);
	BOOL bRetVal = pHttpClient->Request(strURL, CHTTPClient::RequestPostMethodMultiPartsFormData);
	//pHttpClient->Request("http://localhost/simpleupload/Receiver.aspx", CHTTPClient::RequestPostMethodMultiPartsFormData);

	VARIANT_BOOL bBusy = true;
	int ix = 300;
	while (bBusy)
	{
		::Sleep(100);
		pBrowser->get_Busy(&bBusy);
		if (--ix <= 0)
			break;
	}

	if (!bRetVal)
	{
		m_strErrorMsg.Format("Failed to send project to the website.");
		return false;
	}

	CComPtr<IDispatch> spDisp;

	hr = pBrowser->get_Document(&spDisp);
	if (FAILED(hr) || !spDisp)
	{
		delete pHttpClient;
		return false;
	}

	CComQIPtr<IHTMLDocument2> spDoc(spDisp);
	if (!spDoc)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		delete pHttpClient;
		return false;
	}
	
	CComPtr<IHTMLElement> spElem;
	hr = spDoc->get_body(&spElem);
	if (FAILED(hr) || !spDisp)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		delete pHttpClient;
		return false;
	}

	CString strTxt;
	CComBSTR bstr;
	spElem->get_innerHTML(&bstr);
	strTxt = bstr;

#ifdef _DEBUG
	spElem->get_innerText(&bstr);
	strTxt = bstr;
#endif

	delete pHttpClient;

	if (strTxt.Find("<FYS_DATASTREAMACKNOWLEDGMENT") < 0)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		return false;
	}

	strTxt = strTxt.Mid(strTxt.Find("<FYS_DATASTREAMACKNOWLEDGMENT"));

	CString strSrchPtrn("//FYS_DATASTREAMACKNOWLEDGMENT");
	CXMLDocument* pXMLDoc = new CXMLDocument;
	pXMLDoc->LoadString(strTxt);
	pXMLDoc->RegisterCallback(MyXMLCallback, (LPARAM)this);
	if (pXMLDoc->WalkTree(strSrchPtrn) != S_OK)
	{
		pXMLDoc->SetFYSError();
		m_strErrorMsg = pXMLDoc->GetErrorMsg();
		delete pXMLDoc;
		return false;
	}

	delete pXMLDoc;
	return true;
}