void CWordManager::WordEditorInsertActiveElement(void)
{
	CElementManager & em = ((CReportAsistentApp *) AfxGetApp())->m_pGeneralManager->ElementManager;
	LPCTSTR strElementName = getLastElementName();

	//load element
	int element_index = em.ElementIdFromName(strElementName);
	MSXML2::IXMLDOMElementPtr active_element = 
		em.CreateEmptyElement(element_index);

	
	//load document
	MSXML2::IXMLDOMDocument2Ptr doc;
	doc.CreateInstance(_T("Msxml2.DOMDocument"));
	em.LoadSkeletonDTD((MSXML2::IXMLDOMDocumentPtr &) doc);
	
	//insert element to chapter and document
	doc->documentElement->
		appendChild(em.CreateEmptyElement(ELID_CHAPTER))->
			appendChild(active_element);


	//configure by dialog
	if (CSkeletonDoc::EditActiveElement(active_element))
	{
		//transform and generate
		CAElTransform transform(active_element);

		transform.DoAllTransnformations();

#ifdef _DEBUG
		MSXML2::IXMLDOMParseErrorPtr err = doc->validate();

		if (err->errorCode != S_OK)
		{
			AfxMessageBox(err->reason);
			AfxMessageBox(active_element->selectSingleNode("output")->xml);
		}
#endif
	
		GenerateXMLStringToWordEditor(active_element->xml);
	}

	
	
	active_element.Release();
	doc.Release();
}
Ejemplo n.º 2
0
MSXML2::IXMLDOMDocument2Ptr ValidateConfigXML()
{
	wchar_t moduleFileName[MAX_PATH] = {0};
	if(0 == GetModuleFileNameW(GetModuleHandle(_T("TestConnectSdk.dll")/*"TestConnectAPITool.dll"*/), moduleFileName, MAX_PATH))
		throw Workshare::Exception(_T("Failed to obtain the filename of the current module"));
	CStdStringW schemaUrl;
	schemaUrl.Format(L"res://%s/ConnectAPITestTool.xsd", moduleFileName);

	MSXML2::IXMLDOMDocument2Ptr spConfigSchema;
	HRESULT hr = spConfigSchema.CreateInstance(__uuidof(MSXML2::DOMDocument60));
	if(FAILED(hr))
		throw Workshare::ClassNotFoundException(_T("Msxml2.DOMDocument.6.0"), _T("Failed to create an XML dom object."));
	if(VARIANT_TRUE != spConfigSchema->load(schemaUrl.c_str()))
		ThrowMSXMLParseError(spConfigSchema->parseError, _T("Failed to load 'ConnectAPITestTool.xsd'."));

	MSXML2::IXMLDOMSchemaCollection2Ptr spSchemaCollection;
	hr = spSchemaCollection.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60));
	if(FAILED(hr))
		throw Workshare::ClassNotFoundException(_T("Msxml2.XMLSchemaCache.6.0"), _T("Failed to create an XML schema collection."));
	hr = spSchemaCollection->add(L"", spConfigSchema.GetInterfacePtr());
	if(S_OK != hr)
		throw Workshare::Exception(_T("Failed to add 'ConnectAPITestTool.xsd' to schema collection."));

	MSXML2::IXMLDOMDocument2Ptr spConfigXML;
	hr = spConfigXML.CreateInstance(__uuidof(MSXML2::DOMDocument60));
	if(FAILED(hr))
		throw Workshare::ClassNotFoundException(_T("Msxml2.DOMDocument.6.0"), _T("Failed to create an XML dom object."));
	spConfigXML->async = VARIANT_FALSE;
	spConfigXML->resolveExternals = VARIANT_FALSE;
	spConfigXML->validateOnParse = VARIANT_FALSE;
	spConfigXML->schemas = spSchemaCollection.GetInterfacePtr();
	if(VARIANT_TRUE != spConfigXML->load(L"ConnectAPITestTool.xml"))
		ThrowMSXMLParseError(spConfigXML->parseError, _T("Failed to load 'ConnectAPITestTool.xml'."));

	MSXML2::IXMLDOMParseErrorPtr spError = spConfigXML->validate();
	if(S_OK != spError->errorCode)
		ThrowMSXMLParseError(spError, _T("Failed to validate 'ConnectAPITestTool.xml'."));

	return spConfigXML;
}