// saves a list of Word styles to configutation XML file
BOOL CWordManager::saveStylesToXML(LPCTSTR file_path)
{
	CString XMLString = "";
	XMLString += "<word_styles>";
		XMLString += "<templates>";
			XMLString += m_WordTemplates.getItemsInXML();
		XMLString += "</templates>";

		XMLString += "<paragraph_styles>";
			XMLString += m_WordParagraphStyles.getItemsInXML();
		XMLString += "</paragraph_styles>";

		XMLString += "<character_styles>";
			XMLString += m_WordCharacterStyles.getItemsInXML();
		XMLString += "</character_styles>";
	XMLString += "</word_styles>";

	CString FName;	// jmeno (cesta) ke konfig. souboru
	FName = file_path;

	MSXML2::IXMLDOMDocumentPtr pXMLDom;  // koren XML stromu
	HRESULT hr;
    
      //Vytvori COM objekt (resp. instanci objektu)
    hr = pXMLDom.CreateInstance(_T("Msxml2.DOMDocument"));
    if (FAILED(hr)) 
       return FALSE;
    pXMLDom->async = VARIANT_FALSE;
   
       //nacti DOM ze stringu
    if ( pXMLDom->loadXML((_bstr_t) XMLString) != VARIANT_TRUE)
	{
		pXMLDom.Release();
		return FALSE;
	}
	
	BOOL ret = FALSE;

	try
	{
		ret = S_OK == pXMLDom->save((LPCTSTR) FName);
	}
	catch(...)
	{
		ret = FALSE;
	}
	
	pXMLDom.Release();

	return ret;
}
BOOL APBuf::setBuffer(BSTR str, MSXML2::IXMLDOMDocumentPtr & xml)
{
	
	xml.CreateInstance(_T("Msxml2.DOMDocument"));
	xml->async = VARIANT_FALSE; // default - true,
	//vytvoreni XML DOM z nacteneho XML stringu

	CDirectoriesManager & m = ((CReportAsistentApp *) AfxGetApp())->m_pGeneralManager->DirectoriesManager;
	CString str_b = str;
	CFile f;
	f.Open(m.getXMLFilesDirectory() + "\\plug_out_example1.xml", CFile::modeWrite |CFile::modeCreate);
	f.Write((LPCTSTR) str_b, str_b.GetLength());
	f.Close();


	HRESULT hRes=xml->loadXML(str);
	if (xml->parseError->errorCode != S_OK)
	{
		if ((str == NULL) || (* str == 0)) return FALSE;

		CReportAsistentApp::ReportError(IDS_SIMPLE_FILTER_FAILED_SOURCE_LOAD, (LPCTSTR) xml->parseError->reason);

		xml.Release();
		xml = NULL;	

		return FALSE;
	}

	return TRUE;
}
// loads lists of Word styles from configuration XML file
BOOL CWordManager::loadStylesFromXML(LPCTSTR XMLFilePath)
{
	BOOL result = FALSE;	// return value
	CString FName;	// jmeno (cesta) ke konfig. souboru
	FName = XMLFilePath;

	MSXML2::IXMLDOMDocumentPtr pXMLDom;  // koren XML stromu
	MSXML2::IXMLDOMElementPtr pNode;	// korenovy element
	MSXML2::IXMLDOMNodeListPtr pChildren;  // seznam podelementu korenoveho elementu
	MSXML2::IXMLDOMNodeListPtr pChildrenItems;  // seznam podelementu elementu - vstupuje do funkce pro nacitani StringTable
	MSXML2::IXMLDOMElementPtr pChild;	//  podelement korenoveho elementu

	int i = 0;	// indexova promenna
	_variant_t  Atr_val;	// textova hodnota atributu
	HRESULT hr;
    
      //Vytvori COM objekt (resp. instanci objektu)
    hr = pXMLDom.CreateInstance(_T("Msxml2.DOMDocument"));
    if (FAILED(hr)) 
       return FALSE;
    pXMLDom->async = VARIANT_FALSE;
   
       //nacti DOM ze souboru
    if ( pXMLDom->load((LPCTSTR) FName) == VARIANT_TRUE)
	{
		pNode = pXMLDom->GetdocumentElement();
		if (pNode != NULL)
		{
			if (pNode->baseName == (_bstr_t) "word_styles") // spravny nazev korenoveho elementu
			{
				pChildren = pNode->childNodes;	// ziskani seznamu potomku
				pChild = NULL;
				while((pChild = pChildren->nextNode()) != NULL)  // zpracovavaji se potomci
				{
					pChildrenItems = pChild->childNodes;
					if (pChild->baseName == (_bstr_t) "templates")
						m_WordTemplates.loadItemsFromXML(pChildrenItems);

					else if (pChild->baseName == (_bstr_t) "paragraph_styles")
						m_WordParagraphStyles.loadItemsFromXML(pChildrenItems);

					else if (pChild->baseName == (_bstr_t) "character_styles")
						m_WordCharacterStyles.loadItemsFromXML(pChildrenItems);
					
				}
				result = TRUE;
			}
		}
	}

	pXMLDom.Release();

	return result;
}
示例#4
0
int CSOAPUtil::ParseSOAPRequest(char* xml, int xmlSize, SOAP_REQUEST_INFO* info)
{
    int res = NO_ERR;

    MSXML2::IXMLDOMDocumentPtr xmlDoc;
    HRESULT hr = xmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument);
    if(FAILED(hr)) {
        return ERR_FALSE;
    }
    xmlDoc->put_async(VARIANT_FALSE);
    xmlDoc->put_preserveWhiteSpace(VARIANT_TRUE);

    if( LoadDOMDocument(xml, xmlSize, xmlDoc) != NO_ERR ) {
        xmlDoc.Release();
        xmlDoc = NULL;
        return ERR_FALSE;
    }

    //���
    MSXML2::IXMLDOMElementPtr pElemRoot;
    MSXML2::IXMLDOMNodePtr mediaNode = NULL;

    xmlDoc->get_documentElement(&pElemRoot);
    if( pElemRoot == NULL ) {
        res = ERR_FALSE;
        goto Err_End;
    }

    for( int i=0; i<pElemRoot->childNodes->length; i++ ) {
        MSXML2::IXMLDOMNodePtr bodyNode = pElemRoot->childNodes->Getitem(i);
        CComBSTR localName;
        bodyNode->get_baseName(&localName);
        if( localName == NULL ) {
            continue;
        }
        if(CompareNoCase(L"Body", localName.m_str) == 0 ) {
            for( int j=0; j<bodyNode->childNodes->length; j++ ) {
                MSXML2::IXMLDOMNodePtr actionNode = bodyNode->childNodes->Getitem(j);
                CComBSTR actionName;
                actionNode->get_baseName(&actionName);
                if( actionName == NULL ) {
                    continue;
                }

                info->actionName = actionName;
                for( int k=0; k<actionNode->childNodes->length; k++) {
                    MSXML2::IXMLDOMNodePtr argNode = actionNode->childNodes->Getitem(k);
                    CComBSTR argName;
                    argNode->get_baseName(&argName);
                    if( argName == NULL ) {
                        continue;
                    }

                    CComBSTR argVal;
                    argNode->get_text(&argVal);

                    info->argList.insert(pair<wstring,wstring>(argName.m_str, argVal.m_str));
                }
            }
            break;
        }
    }

Err_End:
    xmlDoc.Release();
    xmlDoc = NULL;

    return res;
}
// InitSourcesTab
BOOL CDataSourcesManager::initSourcesTab(LPCTSTR config_file_path)
{
	CString FName;	// jmeno (cesta) ke konfig. souboru
	FName = config_file_path;
	BSTR FileName = FName.AllocSysString();

   // nacteni konfiguracniho souboru zdroju

	MSXML2::IXMLDOMDocumentPtr pXMLDom;  // koren XML stromu
	MSXML2::IXMLDOMElementPtr pNode;	// korenovy element
	MSXML2::IXMLDOMNodeListPtr pChildren;  // seznam podelementu korenoveho elementu
	MSXML2::IXMLDOMElementPtr pChild;	//  podelement korenoveho elementu

    int i = 0;	// indexova promenna
	_variant_t  Atr_val;	// textova hodnota atributu
	HRESULT hr;
	
      //Vytvori COM objekt (resp. instanci objektu)
    hr = pXMLDom.CreateInstance(_T("Msxml2.DOMDocument"));
    if (FAILED(hr)) 
       return FALSE;
    pXMLDom->async = VARIANT_FALSE;
   
       //nacti DOM ze souboru
	if ( pXMLDom->load((LPCTSTR) FName) == VARIANT_TRUE)
    {
		pNode = pXMLDom->GetdocumentElement();
		if (pNode != NULL)
		{
			if (pNode->baseName == (_bstr_t) "SOURCES_LIST") // spravny nazev korenoveho elementu
			{
				pChildren = pNode->childNodes;	// ziskani seznamu potomku
				pChild = NULL;
				while((pChild = pChildren->nextNode()) != NULL)  // zpracovavaji se potomci
				{
					if(pChild->baseName == (_bstr_t) "SOURCE")  // definice polozky v tabulce zdroju
					{
						// pridani prvku do tabulky zdroju
						SourcesTab.Add(new CSourceRec);
							// PUBLIC_ID
						Atr_val = pChild->getAttribute("PUBLIC_ID");
						if(Atr_val.vt != VT_NULL)
							SourcesTab[i]->PublicID = (BSTR) (_bstr_t) Atr_val;
							// PERZISTENT_ID
						Atr_val = pChild->getAttribute("PERZISTENT_ID");
						if(Atr_val.vt != VT_NULL)
							SourcesTab[i]->PerzistID = (BSTR) (_bstr_t) Atr_val;

							// PLUGIN_ID
						Atr_val = pChild->getAttribute("PLUGIN_ID");
						if(Atr_val.vt != VT_NULL)
							SourcesTab[i]->PluginID = (BSTR) (_bstr_t) Atr_val;

						i++;
					}
				}
			}


			//dedek: nacteni default source

			MSXML2::IXMLDOMElementPtr el_default_source = pNode->selectSingleNode("DEFAULT_SOURCE");
			if (el_default_source)
				setDefaultSource((public_source_id_t) (LPCTSTR) (_bstr_t) el_default_source->getAttribute("PUBLIC_ID"));



		}
	}

	SysFreeString(FileName);
	pXMLDom.Release();

	// nastaveni odkazu na tabulku zasuvek prvkum z tabulky zdroju
	
	for(int j=0; j<= SourcesTab.GetUpperBound(); j++)	// pres polozky v tabulce zdroju
	{
		for(int k=0; k<=PlugsTab.GetUpperBound(); k++)
		{
			if(SourcesTab[j]->PluginID == PlugsTab[k].PluginName)
			{
				SourcesTab[j]->PluginIndex = k;	// nastaveni indexu v tabulce zasuvek
				break;
			}
		}
		
	}

	return TRUE;
}
/**Read the XML config file. Currently contains keyboard choices.*/
void read_config_file()
{
	TrainerConfig *result = new TrainerConfig();

	CoInitialize(NULL);

	//read XML
	MSXML2::IXMLDOMDocumentPtr spXMLDoc;
	spXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
	if (!spXMLDoc->load("ent-config.xml"))
	{
		write_text_to_log_file("No config found, using defaults");
		config = result; //the default config
	}

	IXMLDOMNodeListPtr nodes = spXMLDoc->selectNodes(L"//ent-config/keys/key");

	long length;
	nodes->get_length(&length);
	for (int i = 0; i < length; i++)
	{
		IXMLDOMNode *node;
		nodes->get_item(i, &node);
		IXMLDOMNamedNodeMap *attribs;
		node->get_attributes(&attribs);

		long length_attribs;
		attribs->get_length(&length_attribs);

		char *attrib_key_func = NULL;
		char *attrib_key_value = NULL;

		for (long j = 0; j < length_attribs; j++)
		{
			IXMLDOMNode *attribNode;
			attribs->get_item(j, &attribNode);
			attribNode->get_nodeName(&bstr);
			if (wcscmp(bstr, L"function") == 0)
			{
				VARIANT var;
				VariantInit(&var);
				attribNode->get_nodeValue(&var);
				attrib_key_func = _com_util::ConvertBSTRToString(V_BSTR(&var));
			}
			else if (wcscmp(bstr, L"value") == 0)
			{
				VARIANT var;
				VariantInit(&var);
				attribNode->get_nodeValue(&var);
				attrib_key_value = _com_util::ConvertBSTRToString(V_BSTR(&var));
			}
			SysFreeString(bstr);
			attribNode->Release();
		}
		
		if (attrib_key_func != NULL && attrib_key_value != NULL)
		{
			result->get_key_config()->set_key(attrib_key_func, attrib_key_value);
		}
		
		delete attrib_key_func;
		delete attrib_key_value;

		attribs->Release();
		node->Release();
	}

	//nodes->Release(); //don't do this, it crashes on exit
	spXMLDoc.Release();
	CoUninitialize();
	
	config = result;
}