CStdString SmartTagParser::GetNamespacePrefix()
{
    if (m_spXMLDom == NULL)
    {
        CStdString msg;
        msg.Format(_T("SmartTagParser::GetNamespacePrefix - The XML document pointer is null."));
        throw Workshare::NullReferenceException(msg);
    }

    MSXML2::IXMLDOMElementPtr spElement = m_spXMLDom->firstChild;
    if (spElement == NULL)
    {
        CStdString msg;
        msg.Format(_T("SmartTagParser::GetNamespacePrefix - Failed to get the first node of the document."));
        throw Workshare::Exception(msg);
    }

    MSXML2::IXMLDOMNamedNodeMapPtr spAttributes = spElement->attributes;
    if (spAttributes == NULL)
    {
        spElement.Release();

        CStdString msg;
        msg.Format(_T("SmartTagParser::GetNamespacePrefix - Failed to get attributes of the first child of the document."));
        throw Workshare::Exception(msg);
    }

    MSXML2::IXMLDOMAttributePtr spAttribute = spAttributes->item[0];
    if (spAttribute == NULL)
    {
        spElement.Release();
        spAttributes.Release();

        CStdString msg;
        msg.Format(_T("SmartTagParser::GetNamespacePrefix - Failed to get attributes of the first child of the document."));
        throw Workshare::Exception(msg);
    }

    CStdString sFullNamespace = spAttribute->xml;
	HRESULT hr = m_spXMLDom->raw_setProperty(_T("SelectionNamespaces"), _variant_t(sFullNamespace.c_str()));
	if (FAILED(hr))
	{
		CStdString message;
		message.Format(_T("SmartTagParser::SmartTagParser - Failed to set namespace : %s."), sFullNamespace.c_str());
		throw Workshare::Com::ComException(message.c_str(), hr, m_spXMLDom);
	}

    int iPosStart = sFullNamespace.Find(_T(":"));
    int iPosEnd = sFullNamespace.Find(_T("="));

    CStdString sPrefix = sFullNamespace.Mid(iPosStart+1, iPosEnd - (iPosStart+1));

    spElement.Release();
    spAttributes.Release();
    spAttribute.Release();

    return sPrefix;
}
//dedek:
BOOL CDataSourcesManager::saveSourcesTab()
{
	BOOL ret = TRUE;

	MSXML2::IXMLDOMDocumentPtr pXMLDom;
    pXMLDom.CreateInstance(_T("Msxml2.DOMDocument"));
	
	MSXML2::IXMLDOMElementPtr root_el;	// korenovy element
	root_el = pXMLDom->createElement("SOURCES_LIST");
	pXMLDom->appendChild(root_el);

	MSXML2::IXMLDOMElementPtr source_el;	// source element
	source_el = pXMLDom->createElement("SOURCE");
	
	//atributy
	MSXML2::IXMLDOMAttributePtr attr;
	
	attr = pXMLDom->createAttribute("PUBLIC_ID");
	source_el->setAttributeNode(attr);
	attr.Release();

	attr = pXMLDom->createAttribute("PERZISTENT_ID");
	source_el->setAttributeNode(attr);
	attr.Release();

	attr = pXMLDom->createAttribute("PLUGIN_ID");
	source_el->setAttributeNode(attr);
	attr.Release();

	for (int a=0; a<getSourcesCount(); a++)
	{
		MSXML2::IXMLDOMElementPtr e = source_el->cloneNode(VARIANT_TRUE);

		e->setAttribute("PUBLIC_ID", (LPCTSTR) getSourcePublicID(a));
		e->setAttribute("PERZISTENT_ID", (LPCTSTR) getSourcePersistentID(a));
		e->setAttribute("PLUGIN_ID", (LPCTSTR) getSourcePlugin(a));
		root_el->appendChild(e);

		e.Release();

	}
	source_el.Release();



	//default zdroj:
	MSXML2::IXMLDOMElementPtr default_source;
	default_source = pXMLDom->createElement("DEFAULT_SOURCE");

	MSXML2::IXMLDOMAttributePtr src_attr;	
	src_attr = pXMLDom->createAttribute("PUBLIC_ID");
	src_attr->value = (LPCTSTR) getDefaultSource();
	default_source->setAttributeNode(src_attr);
	src_attr.Release();
	root_el->appendChild(default_source);

	default_source.Release();

	CDirectoriesManager & m = ((CReportAsistentApp *) AfxGetApp())->m_pGeneralManager->DirectoriesManager;
	
	// save list of data sources into config. file "ConfigDir/sources.xml"
	try
	{
		ret = S_OK == pXMLDom->save((LPCTSTR) m.getSourcesConfigFilePath());
	}
	catch(...)
	{
		CReportAsistentApp::ReportError(IDS_DSLISTSAVE_ERR);
	}


	root_el.Release();
	return ret;
}
BOOL CAttributeLinkTableDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	if (! m_bShowTarget) m_TargetCombo.EnableWindow(FALSE);
	
	InitBaseDialog(m_AttributesList, m_TargetCombo);


	//dedek: inicializuj CaptionsList
	CRect r;
	m_CaptionsList.GetWindowRect(& r);
	m_CaptionsList.InsertColumn(CAPTLIST_CL_CAPTION, "caption", LVCFMT_LEFT, r.Width()/3 -3);
	m_CaptionsList.InsertColumn(CAPTLIST_CL_VALUE, "value", LVCFMT_LEFT, r.Width()/3 -3);
	m_CaptionsList.InsertColumn(CAPTLIST_CL_NAME, "name", LVCFMT_LEFT, r.Width()/3 -3);


	//napln CaptionsList hodnotami
	m_CaptionsList.SetExtendedStyle(LVS_EX_FULLROWSELECT);

	MSXML2::IXMLDOMNodeListPtr links = m_SelXMLElm->selectNodes("link");

	CString target_id;
	m_TargetCombo.GetWindowText(target_id);

	int a;
	for (a=0; a < links->length; a++)
	{
		MSXML2::IXMLDOMElementPtr link = links->item[a];

		//caption
		int item = m_CaptionsList.InsertItem(a, (_bstr_t) link->getAttribute("caption"));
		
		//attr_name
		CString attr_name = (LPCTSTR) (_bstr_t) link->getAttribute("attr_name");
		m_CaptionsList.SetItemText(item, CAPTLIST_CL_NAME, attr_name);

		//value
		CString query_str;
		query_str.Format("id(\"%s\")/attributes/element_attributes/attribute[@name=\"%s\"]/@value", target_id, attr_name);

		MSXML2::IXMLDOMNodePtr value_attr = m_SelXMLElm->ownerDocument->selectSingleNode((LPCTSTR) query_str);

		if (value_attr != NULL)
		{
			m_CaptionsList.SetItemText(item, CAPTLIST_CL_VALUE, value_attr->text);
			value_attr.Release();
		}

		
		link.Release();
	}


	//napln style combo

	CElementManager & m = ((CReportAsistentApp *) AfxGetApp())->m_pGeneralManager->ElementManager;
	int item = CB_ERR;
	for (a=0; a < m.getAttrLinkTableStylesCount(); a++)
	{
		item = m_StyleCombo.AddString(m.getAttrLinkTableStyleName(a));
	}

	//vyber style
	int sel = m_StyleCombo.SelectString(-1, (_bstr_t) m_SelXMLElm->getAttribute("style"));
	//vyber se nezdaril => kdyz exituje nejaky styl vyber prvni
	if ((sel == CB_ERR) && (item != CB_ERR))
	{
		m_StyleCombo.SelectString(-1, m.getAttrLinkTableStyleName(0));
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}