예제 #1
0
STDMETHODIMP CXMLHttpRequest::get_responseXML(IDispatch **ppBody)
{
	ATLTRACE(_T("CXMLHttpRequest::get_responseXML\n"));

	if (NULL == ppBody)
		return E_POINTER;

	*ppBody = NULL;

	// check if there is a send active 
	if (NULL != m_hThread) {
		DWORD exitCode = 0;
		BOOL rc = ::GetExitCodeThread(m_hThread, &exitCode);
		if (!rc || STILL_ACTIVE == exitCode) 
			return E_PENDING;
		
		::CloseHandle(m_hThread);
		m_hThread = NULL;
	}

	BSTR text = NULL;
	HRESULT hr = get_responseText(&text);
	if (S_OK != hr || NULL == text)
		return hr;

	CXMLDOMDocumentObj *pObj = NULL;
	hr = CXMLDOMDocumentObj::CreateInstance(&pObj);
	if (S_OK == hr) {	
		pObj->AddRef();
		VARIANT_BOOL isSuccessful = VARIANT_FALSE;
		hr = pObj->loadXML(text, &isSuccessful);
		if (S_OK == hr && VARIANT_TRUE == isSuccessful) {
			*ppBody = pObj;
			(*ppBody)->AddRef();
		}
		pObj->Release();
	}

	::SysFreeString(text);

	return hr;
}
예제 #2
0
파일: XMLDOMUtil.cpp 프로젝트: mydw/mydw
HRESULT wrapNode(IXMLDOMDocument *pDoc, DOMNode* node, REFIID iid, LPVOID *pVal)
{
	HRESULT hr = S_OK;
	if (NULL == pVal)
		return E_POINTER;

	*pVal = NULL;
	short type = node->getNodeType();

	// the way we are constructing the wrappers is kind of fishy but oh well...
	// the various IBM DOM wrapper classes don't ever add any members or have
	// any v-tables so what we are doing should be safe.  There isn't any other
	// way as far as I can tell to do this....

	switch(type)
	{
	case DOMNode::ELEMENT_NODE:
	{
		CXMLDOMElement *pObj = NULL;
		hr = CPooledXMLDOMElementObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->element = static_cast<DOMElement*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::ATTRIBUTE_NODE:
	{
		CXMLDOMAttribute *pObj = NULL;
		hr = CPooledXMLDOMAttributeObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->attr = static_cast<DOMAttr*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::TEXT_NODE:
	{
		CXMLDOMText *pObj = NULL;
		hr = CPooledXMLDOMTextObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->text = static_cast<DOMText*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::CDATA_SECTION_NODE:
	{
		CXMLDOMCDATASection *pObj = NULL;
		hr = CPooledXMLDOMCDATASectionObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->cdataSection = static_cast<DOMCDATASection*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::ENTITY_REFERENCE_NODE:
	{
		CXMLDOMEntityReference *pObj = NULL;
		hr = CPooledXMLDOMEntityReferenceObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->entityReference = static_cast<DOMEntityReference*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::ENTITY_NODE:
	{
		CXMLDOMEntity *pObj = NULL;
		hr = CPooledXMLDOMEntityObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);
		
		try
		{
			pObj->entity = static_cast<DOMEntity*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::PROCESSING_INSTRUCTION_NODE:
	{
		CXMLDOMProcessingInstruction *pObj = NULL;
		hr = CPooledXMLDOMProcessingInstructionObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->processingInstruction = static_cast<DOMProcessingInstruction*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::COMMENT_NODE:
	{
		CXMLDOMComment *pObj = NULL;
		hr = CPooledXMLDOMCommentObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->comment = static_cast<DOMComment*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::DOCUMENT_NODE:
	{
		CXMLDOMDocumentObj *pObj = NULL;
		hr = CXMLDOMDocumentObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->m_Document = static_cast<XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::DOCUMENT_TYPE_NODE:
	{
		CXMLDOMDocumentTypeObj *pObj = NULL;
		hr = CXMLDOMDocumentTypeObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->documentType = static_cast<DOMDocumentType*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::DOCUMENT_FRAGMENT_NODE:
	{
		CXMLDOMDocumentFragmentObj *pObj = NULL;
		hr = CXMLDOMDocumentFragmentObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->documentFragment = static_cast<DOMDocumentFragment*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}
	case DOMNode::NOTATION_NODE:
	{
		CXMLDOMNotationObj *pObj = NULL;
		hr = CXMLDOMNotationObj::CreateInstance(&pObj);
		if (S_OK != hr)
			return hr;
	
		pObj->AddRef();
		pObj->SetOwnerDoc(pDoc);

		try
		{
			pObj->notation = static_cast<DOMNotation*> (node);
		}
		catch(DOMException& ex)
		{
			pObj->Release();
			return MakeHRESULT(ex);
		}
		catch(...)
		{
			pObj->Release();
			return E_FAIL;
		}
	
		hr = pObj->QueryInterface(iid, pVal);
		if (S_OK != hr)
			*pVal = NULL;

		pObj->Release();
		break;
	}

	default:
		hr = E_NOTIMPL;
		break;
	}

	return hr;
}