void CSimpleFilterDialog::SaveSelection(void)
{
	POSITION pos = m_ResultList.GetFirstSelectedItemPosition(); 

	
	//okopiruje vzorovy element selection
	MSXML2::IXMLDOMElementPtr selection_elem = m_active_element->ownerDocument->createElement("selection");
	MSXML2::IXMLDOMAttributePtr id_attr = m_active_element->ownerDocument->createAttribute("id");
	selection_elem->setAttributeNode(id_attr);
	id_attr.Release();
	
	//vymaze vsechny selection
	MSXML2::IXMLDOMNodeListPtr list = m_cloned_active_element->selectNodes("filter[@type='simple']/selection");
	MSXML2::IXMLDOMSelection * sel;
	list.QueryInterface(__uuidof(MSXML2::IXMLDOMSelection), &sel);
	sel->removeAll();
	sel->Release();

	MSXML2::IXMLDOMNodePtr filter = m_cloned_active_element->selectSingleNode("filter[@type='simple']");
	
	while (pos)
	{
		int nItem = m_ResultList.GetNextSelectedItem(pos);

		selection_elem->setAttribute("id", (LPCTSTR) m_ResultList.GetItemText(nItem, 0));
		filter->appendChild(selection_elem->cloneNode(VARIANT_FALSE));
	}

	selection_elem.Release();

}
Beispiel #2
0
BOOL CAddItem::AddSeparator(MSXML2::IXMLDOMNodePtr node, LPCTSTR strSeparator = _T("\n   "))
{
   BOOL bResult = FALSE;
   MSXML2::IXMLDOMNodePtr elementText = docPtr->createTextNode(strSeparator);
   hr = node->appendChild(elementText);
   bResult = SUCCEEDED(hr);
   return bResult;
}
Beispiel #3
0
BOOL CAddItem::AddElement(MSXML2::IXMLDOMNodePtr item, LPCTSTR tstrTagName, LPCTSTR tstrTagText)
{
   BOOL bResult = FALSE;
   MSXML2::IXMLDOMNodePtr element = docPtr->createElement(tstrTagName);    
   if(element != NULL)
   {
      MSXML2::IXMLDOMNodePtr elementText = docPtr->createTextNode(tstrTagText);
      if(elementText != NULL)
      {
         hr = element->appendChild(elementText);
         if(SUCCEEDED(hr))
         {  
            hr = item->appendChild(element);
            bResult = SUCCEEDED(hr);
         }
      }
   }
   return bResult;
}
MSXML2::IXMLDOMNodePtr CXmlBase::InsertEnterAndTabs(MSXML2::IXMLDOMNodePtr pParentNode, int nLevel)
{
	HRESULT hr = S_OK;
	MSXML2::IXMLDOMDocument2Ptr pDoc = NULL;
	MSXML2::IXMLDOMTextPtr pTabsText = NULL;
	MSXML2::IXMLDOMNodePtr pTabsNode = NULL;
	MSXML2::IXMLDOMElementPtr pElement = NULL;
	CString strText(_T("")), strTabs(_T(""));
	CComBSTR bstrText;

	if (nLevel < 0 
		|| pParentNode == NULL) return NULL;

	for (int i=0; i<nLevel; i++)
	{
		strTabs += _T("\t");
	}
	strText.Format(_T("%s%s"), _T("\r\n"), (LPCTSTR)strTabs);
	bstrText = _bstr_t(strText).GetBSTR();

	try
	{
		pDoc = pParentNode->GetownerDocument();
		if (pDoc == NULL) return NULL;

		pTabsText = pDoc->createTextNode((LPCTSTR)strText);
		if (pTabsText == NULL) return NULL;
		pTabsNode = pParentNode->appendChild(pTabsText);

		
		//hr = pDoc->raw_createTextNode(bstrText.m_str, &pTabsText);
		//if (FAILED(hr) || pTabsText == NULL) return NULL;
		//pElement = pTabsText;
		//pTabsNode = pParentNode->appendChild(pElement);

		//pTabsNode = pDoc->createTextNode((LPCTSTR)strText);  
		//if (pTabsNode == NULL) return NULL;
		//pNode = pNode->appendChild(pTabsNode);
	}
	catch(_com_error &e)
	{
		CString str;
		str.Format(_T("创建xml节点发生异常。\r\nComError:\r\n%s")
			, e.ErrorMessage());
		::MessageBox(NULL,str, g_sAppTitle, MB_OK|MB_ICONERROR);
		return NULL;
	}
	catch(...)
	{
		return NULL;
	}
	return pTabsNode;
}
Beispiel #5
0
BOOL CXmlFile::Export(const CXmlItem* pItem, CXmlNodeWrapper* pNode) const
{
	// own value
	if (pItem->GetValueLen())
		pNode->SetText(pItem->GetValue());
	
	// attributes and items
	POSITION pos = pItem->GetFirstItemPos();
	int nNode = 0;
	
	while (pos)
	{
		const CXmlItem* pXIChild = pItem->GetNextItem(pos);
		ASSERT (pXIChild);
		
		CString sItem = pXIChild->GetName();
		
		if (pXIChild->IsAttribute())
		{
			ASSERT (!pXIChild->GetSibling());
			pNode->SetValue(sItem, pXIChild->GetValue());
		}
		else if (pXIChild->IsCDATA())
		{
			// create a named node to wrap the CDATA
			MSXML2::IXMLDOMNodePtr pChildNode = pNode->InsertNode(nNode++, (LPCTSTR)sItem);
			MSXML2::IXMLDOMCDATASectionPtr pCData = 
				pNode->ParentDocument()->createCDATASection((LPCTSTR)pXIChild->GetValue());
			pChildNode->appendChild(pCData);
		}
		else // node
		{
			while (pXIChild)
			{
				// Valik - Change IXMLDOMNode* to IXMLDOMNodePtr to prevent an ambiguous symbol error (C2872) in VC 7.1
				MSXML2::IXMLDOMNodePtr pChildNode = pNode->InsertNode(nNode++, (LPCTSTR)sItem);
				CXmlNodeWrapper nodeChild(pChildNode);
				ASSERT (nodeChild.IsValid());
				
				Export(pXIChild, &nodeChild);
				
				// siblings
				pXIChild = pXIChild->GetSibling();
			}
		}
	}
	
	return TRUE;
}
Beispiel #6
0
BOOL CAddItem::AddElementAndAttributes(MSXML2::IXMLDOMNodePtr item, LPCTSTR tstrTagName, LPCTSTR tstrTagText)
{
   BOOL bResult = FALSE;
   MSXML2::IXMLDOMNodePtr element = docPtr->createElement(tstrTagName);    
   if(element != NULL)
   {
      MSXML2::IXMLDOMNodePtr elementText = docPtr->createTextNode(tstrTagText);
      if(elementText != NULL)
      {
         element->appendChild(elementText);
         
         bResult  = AddAttribute(element, _T("length"), csLength);
         bResult &= AddAttribute(element, _T("type"),   csType);
         bResult &= AddAttribute(element, _T("url"),    csUrl);
   
         if(bResult)
         {
            hr = item->appendChild(element);
            bResult = SUCCEEDED(hr);
         }
      }
   }
   return bResult;
}
MSXML2::IXMLDOMNodePtr CXmlBase::CreateNode(MSXML2::IXMLDOMNodePtr pParentNode
	, LPCTSTR lpszNodeText)
{
	HRESULT hr = S_OK;
	MSXML2::IXMLDOMDocument2Ptr pDoc = NULL;
	MSXML2::IXMLDOMElementPtr pElement = NULL;
	MSXML2::IXMLDOMNodePtr pNode = NULL;
	CComBSTR bstrNodeText = _bstr_t("node").GetBSTR();

	if (pParentNode == NULL 
		|| lpszNodeText == NULL) return NULL;

	bstrNodeText = lpszNodeText;
	if (bstrNodeText.Length() == 0) return NULL;

	try
	{
		pDoc = pParentNode->GetownerDocument();
		if (pDoc == NULL) return NULL;
		//hr = pDoc->raw_createElement(bstrNodeText.m_str, &pElement);
		//if (FAILED(hr) || pElement == NULL) return NULL;
		pNode = pDoc->createNode(NODE_ELEMENT, bstrNodeText.m_str, _T(""));
		if (pNode == NULL) return NULL;
		pNode = pParentNode->appendChild(pNode);
	}
	catch(_com_error &e)
	{
		CString str;
		str.Format(_T("创建xml节点发生异常。\r\nComError:\r\n%s")
			, e.ErrorMessage());
		::MessageBox(NULL,str, g_sAppTitle, MB_OK|MB_ICONERROR);
		return NULL;
	}
	catch(...)
	{
		return NULL;
	}
	return pNode;
}