Ejemplo n.º 1
0
	TEST_FIXTURE(XmlFixture, CreateChild2)
	{
		MSXML2::IXMLDOMNode *node = 0;
		HRESULT hr = XMLHelper::CreateChild(root, &node, _T("test"));
		CHECK_OK(hr);
		CHECK(node);
		node->Release();
		node = 0;
		BSTR query = SysAllocString(_T("//test"));
		MSXML2::IXMLDOMNodeList *nodeList = 0;
		hr = doc->selectNodes(query, &nodeList);
		SysFreeString(query);
		CHECK_OK(hr);
		CHECK(nodeList);
		long length = 0;
		hr = nodeList->get_length(&length);
		CHECK_OK(hr);
		CHECK_EQUAL(1, length);
		hr = nodeList->nextNode(&node);
		CHECK_OK(hr);
		CHECK(node);
		BSTR name = 0;
		hr = node->get_nodeName(&name);
		CHECK_OK(hr);
		CHECK_EQUAL(0, _tcscmp(name, _T("test")));
		SysFreeString(name);
	}
Ejemplo n.º 2
0
//The big issue here will be the whether the input time is local or UTC, there could be problems
//between users in different timezones and the proper realization of template...
//TODO: review code to ensure template is realized properly
void RecurrenceManager::RealizeRecurrences(unsigned __int64 date)
{
	if(date > m_pDataManager->GetDayManagerInstance()->GetToday() - 1)
	{
		SYSTEMTIME st = ModelUtils::I64ToSystemTime(date);
		StringBuffer sb(_T("//recurrence[schedule/@"));
		sb.append(days[st.wDayOfWeek]);
		sb.append(_T("='true']"));

		BSTR xpath = SysAllocString(sb);
		MSXML2::IXMLDOMNodeList *pList = 0;

		HRESULT hr = m_pXMLDoc->selectNodes(xpath, &pList);
		if(hr == S_OK && pList)
		{
			MSXML2::IXMLDOMNode *pNode = 0;
			while((hr = pList->nextNode(&pNode)) == S_OK)
			{
				RealizeRecurrence(pNode, st);
				pNode->Release();
			}
			pList->Release();
		}
	}
}
Ejemplo n.º 3
0
		HRESULT XMLHelper::GetAttribute(MSXML2::IXMLDOMNode *pNode, const TCHAR *pAttr, int *pVal)
		{
			MSXML2::IXMLDOMNamedNodeMap *pAttrMap = 0;
			HRESULT hr = pNode->get_attributes(&pAttrMap);
			if(hr == S_OK)
			{
				BSTR attr = SysAllocString(pAttr);
				MSXML2::IXMLDOMNode *pAttrNode = 0;
				hr = pAttrMap->getNamedItem(attr, &pAttrNode);
				SysFreeString(attr);
				if(hr == S_OK && pAttrNode)
				{
					VARIANTARG varg;
					VariantInit(&varg);
					hr = pAttrNode->get_nodeValue(&varg);
					if(hr == S_OK && varg.vt == VT_BSTR)
					{
						*pVal = varg.bstrVal? _wtoi(varg.bstrVal): 0;
						SysFreeString(varg.bstrVal);
					}
					pAttrNode->Release();
				}
				pAttrMap->Release();
			}
			return hr;
		}
Ejemplo n.º 4
0
void RecurrenceManager::CreateSchedule(MSXML2::IXMLDOMNode *pRecurrence, bool sunday, bool monday, bool tuesday, bool wednesday, bool thursday, bool friday, bool saturday, 
	unsigned short starthour, unsigned short startminute, int duration)
{
	MSXML2::IXMLDOMNode *pNode = 0;
	HRESULT hr = XMLHelper::CreateChild(pRecurrence, &pNode, _T("schedule"));
	if(S_OK == hr && pNode)
	{
		if(sunday)XMLHelper::SetAttribute(pNode, days[0], _T("true"));
		if(monday)XMLHelper::SetAttribute(pNode, days[1], _T("true"));
		if(tuesday)XMLHelper::SetAttribute(pNode, days[2], _T("true"));
		if(wednesday)XMLHelper::SetAttribute(pNode, days[3], _T("true"));
		if(thursday)XMLHelper::SetAttribute(pNode, days[4], _T("true"));
		if(friday)XMLHelper::SetAttribute(pNode, days[5], _T("true"));
		if(saturday)XMLHelper::SetAttribute(pNode, days[6], _T("true"));
		StringBuffer sb(16);
		sb.appendInt(starthour);
		XMLHelper::SetAttribute(pNode, _T("starthour"), sb);
		sb.flush();
		sb.appendInt(startminute);
		XMLHelper::SetAttribute(pNode, _T("startminute"), sb);
		sb.flush();
		sb.appendInt(duration);
		XMLHelper::SetAttribute(pNode, _T("duration"), sb);
		pNode->Release();
	}
}
Ejemplo n.º 5
0
Task::TaskSet * CTaskModel::GetChildren(Task::TaskSet *pSet)
{
	//if(!m_pTaskManager)return pSet;
	MSXML2::IXMLDOMNodeList *pNodeList = 0;
	BSTR xpath = SysAllocString(_T("./task"));
	HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList);
	SysFreeString(xpath);
	MSXML2::IXMLDOMNode *pNode = 0;
	if(pNodeList)
	{
		while((hr = pNodeList->nextNode(&pNode)) == S_OK)
		{
			unsigned __int64 childID = 0;
			XMLHelper::GetAttributeI64(pNode, TASKID, &childID);
			Task *pTask = new(childID) CTaskModel(pNode);
			if(pTask)
			{
				pSet->Add(*pTask);
			}
			pNode->Release();
			pNode = 0;
		}
	}
	pNodeList->Release();
	pNodeList = 0;
	return pSet;
}
Ejemplo n.º 6
0
void RecurrenceManager::CreateRecurrence(const TCHAR *type, const TCHAR *title, const TCHAR *desc, unsigned __int64 parentId, 
	bool sunday, bool monday, bool tuesday, bool wednesday, bool thursday, bool friday, bool saturday, 
	unsigned short starthour, unsigned short startminute, int duration)
{
	MSXML2::IXMLDOMNode *pRecurrence = 0;
	HRESULT hr = XMLHelper::CreateChild(GetRecurrencesNode(), &pRecurrence, _T("recurrence"));
	if(S_OK == hr && pRecurrence)
	{
		XMLHelper::SetAttribute(pRecurrence, _T("type"), type);
		XMLHelper::SetAttributeI64(pRecurrence, _T("recurrenceid"), ModelUtils::GenerateID());
		XMLHelper::SetAttributeI64(pRecurrence, _T("parentid"), parentId);
		MSXML2::IXMLDOMNode *pNode = 0;
		hr = XMLHelper::CreateChild(pRecurrence, &pNode, _T("title"), title);
		if(S_OK == hr && pNode)
		{
			pNode->Release();
		}
		pNode = 0;
		hr = XMLHelper::CreateChild(pRecurrence, &pNode, _T("desc"), desc);
		if(S_OK == hr && pNode)
		{
			pNode->Release();
		}
		CreateSchedule(pRecurrence, sunday, monday, tuesday, wednesday, thursday, friday, saturday, starthour, startminute, duration);
	}
}
Ejemplo n.º 7
0
void XmlParser::Parse(NodeCallback callback, void *data)
{
	MSXML2::IXMLDOMNodeListPtr NodeListPtr;
	BSTR strFindText  = L" ";
	MSXML2::IXMLDOMNode *pIDOMNode = NULL;
	BSTR bstrNodeType;

	assert(m_domDocument != NULL);

	NodeListPtr = m_domDocument->getElementsByTagName(strFindText);	

	for(int i = 0; i < NodeListPtr->length; i++)
	{
		if (pIDOMNode)
			pIDOMNode->Release();

		NodeListPtr->get_item(i, &pIDOMNode);
		pIDOMNode->get_nodeTypeString(&bstrNodeType);

		if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"element") != 0)
			continue;
		
		XmlNode node;
		_parseNode(pIDOMNode, node);
		
		if (callback(node, data) == false)
			break;
	}

	if (pIDOMNode)
			pIDOMNode->Release();	
}
Ejemplo n.º 8
0
//TODO: review usage of TaskIDSet, in particular the local allocation and copying of contents
Task::TaskIDSet CTaskModel::GetAllPrerequisites()
{
	TaskIDSet ts;
	MSXML2::IXMLDOMNodeList *pNodeList = 0;
	BSTR xpath = SysAllocString(_T("ancestor-or-self::task/prerequisite"));
	HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList);
	SysFreeString(xpath);
	MSXML2::IXMLDOMNode *pNode = 0;
	unsigned __int64 id = 0;
	BSTR bstr = 0;
	if(pNodeList)
	{
		while((hr = pNodeList->nextNode(&pNode)) == S_OK)
		{
			if(pNode)
			{
				hr = XMLHelper::GetAttribute(pNode, _T("taskid"), &bstr);
				if(hr == S_OK)
				{
					id = ModelUtils::fromHexString(bstr, wcslen(bstr));
					ts.Add(id);
					id = 0;
					SysFreeString(bstr);
				}
				bstr = 0;
				pNode->Release();
				pNode = 0;
			}
		}
		pNodeList->Release();
	}
	return ts;
}
Ejemplo n.º 9
0
void PlanEntryModelManager::DeleteTimeEntry(unsigned __int64 id)
{
	EnterCriticalSection(&critical_section);
	MSXML2::IXMLDOMNode *pNode = 0;
	StringBuffer conv(32);
	StringBuffer sb(_T("//timeentry[@entryid=\""));
	sb.append(ModelUtils::toHexString(id, conv));
	sb.append(_T("\"]"));
	BSTR xpath = SysAllocString(sb);
	HRESULT hr = m_pXMLDoc->selectSingleNode(xpath, &pNode);
	SysFreeString(xpath);
	if(hr == S_OK && pNode)
	{
		MSXML2::IXMLDOMNode *pOld = 0;
		hr = m_pRoot->removeChild(pNode, &pOld);
		if(hr == S_OK)
		{
			pOld->Release();
			TimeEntryEvent tee(TimeEntryEvent::TIME_ENTRY_DELETE, id);
			NotifyChanged(tee);
		}
		pNode->Release();
	}
	LeaveCriticalSection(&critical_section);
}
Ejemplo n.º 10
0
XmlFixture::XmlFixture()
{
	OleInitialize(0);

	CoCreateInstance(__uuidof(MSXML2::FreeThreadedDOMDocument60), NULL, 
		CLSCTX_SERVER, __uuidof(MSXML2::IXMLDOMDocument2), reinterpret_cast<void **>(&doc));

	BSTR prop = SysAllocString(_T("SelectionNamespaces"));
	VARIANTARG varg;
	VariantInit(&varg);
	varg.vt = VT_BSTR;
	varg.bstrVal = SysAllocString(_T("xmlns:ms='urn:schemas-microsoft-com:xslt'"));
	doc->setProperty(prop, varg);

	VariantInit(&varg);
	varg.vt = VT_I2;
	varg.iVal = MSXML2::NODE_ELEMENT;
	BSTR EMPTY_STR = SysAllocString(_T(""));
	BSTR rootStr = SysAllocString(_T("tasktracker"));
	HRESULT hr = doc->createNode(varg, rootStr, EMPTY_STR, &root);
	SysFreeString(rootStr);
	SysFreeString(EMPTY_STR);
	if(hr == S_OK && root)
	{
		MSXML2::IXMLDOMNode *pOut = 0;
		hr = doc->appendChild(root, &pOut);
		if(hr == S_OK && pOut)
		{
			pOut->Release();
			pOut = 0;
		}
	}

}
Ejemplo n.º 11
0
	TEST_FIXTURE(XmlFixture, CreateChild)
	{
		MSXML2::IXMLDOMNode *node = 0;
		HRESULT hr = XMLHelper::CreateChild(root, &node, _T("test"));
		CHECK_OK(hr);
		CHECK(node);
		node->Release();
	}
Ejemplo n.º 12
0
		HRESULT XMLHelper::GetChildText(MSXML2::IXMLDOMNode *pNode, const TCHAR *pChild, BSTR *pBstr)
		{
			BSTR xpath = SysAllocString(pChild);
			MSXML2::IXMLDOMNode *pChildNode = 0;
			HRESULT hr = pNode->selectSingleNode(xpath, &pChildNode);
			SysFreeString(xpath);
			if(hr == S_OK && pChildNode)
			{
				hr = pChildNode->get_text(pBstr);
				pChildNode->Release();
			}
			return hr;
		}
Ejemplo n.º 13
0
void CTaskModel::AddPrerequisite(unsigned __int64 prereq)
{
	//AddPrerequisite(prereq, true);
	MSXML2::IXMLDOMNode *pNode = 0;
	HRESULT hr = AppendChild(&pNode, PREREQUISITE);
	if(hr == S_OK && pNode)
	{
		StringBuffer temp(32);
		XMLHelper::SetAttribute(pNode, TASKID, ModelUtils::toHexString(prereq, temp));
		pNode->Release();
	}
	//TODO: notify?..
}
Ejemplo n.º 14
0
TimeEntry * PlanEntryModelManager::CreateTimeEntry(
						unsigned __int64 taskID, unsigned __int64 start, unsigned __int64 stop, TCHAR *pTaskname)
{
	MSXML2::IXMLDOMNode *pNode = CreateEntryNode();
	TimeEntry *pEntry = new(pNode) PlanEntryModel(pNode, start, stop, taskID, m_pDataManager->GetUsername(), pTaskname);
	pNode->Release();
	if(pEntry)
	{
		TimeEntryEvent tee(TimeEntryEvent::TIME_ENTRY_ADD, pEntry->GetID(), pEntry);
		NotifyChanged(tee);
	}
	return pEntry;
}
Ejemplo n.º 15
0
void CDialogSettings::LoadXMLSettings(MSXML2::IXMLDOMNamedNodeMap *pam,long lChildNodes)
{
	MSXML2::IXMLDOMNode *pNode = NULL;
	BSTR bstrName;
	BSTR bstrValue;

	for(int i = 1;i < lChildNodes;i++)
	{
		pam->get_item(i,&pNode);

		pNode->get_nodeName(&bstrName);
		pNode->get_text(&bstrValue);

		bool bHandled = false;

		if(m_bSavePosition)
		{
			if(lstrcmpi(bstrName, SETTING_POSITION_X) == 0)
			{
				m_ptDialog.x = NXMLSettings::DecodeIntValue(bstrValue);
				bHandled = true;
			}
			else if(lstrcmpi(bstrName, SETTING_POSITION_Y) == 0)
			{
				m_ptDialog.y = NXMLSettings::DecodeIntValue(bstrValue);
				bHandled = true;
			}
			else if(lstrcmpi(bstrName, SETTING_WIDTH) == 0)
			{
				m_iWidth = NXMLSettings::DecodeIntValue(bstrValue);
				bHandled = true;
			}
			else if(lstrcmpi(bstrName, SETTING_HEIGHT) == 0)
			{
				m_iHeight = NXMLSettings::DecodeIntValue(bstrValue);
				bHandled = true;
			}
		}

		if(!bHandled)
		{
			/* Pass the node name and value to any
			descendant class to handle. */
			LoadExtraXMLSettings(bstrName,bstrValue);
		}
	}

	m_bStateSaved = TRUE;
}
Ejemplo n.º 16
0
	TEST_FIXTURE(XmlFixture, AllocationMapCleaned)
	{
		MSXML2::IXMLDOMNode *taskNode = 0;
		for(unsigned __int64 id = 1; id < 100; ++id)
		{
			HRESULT hr = XMLHelper::CreateChild(root, &taskNode, _T("task"));
			CHECK_OK(hr);
			CTaskModel * tm = new(id) CTaskModel(taskNode, id, 0, _T("Test"), _T("Test"), _T("Test"), 0, 0, 0, 0, 0, false, 3, TASK_STATE_OPEN);
			CHECK(tm);
			delete tm;
			taskNode->Release();
			taskNode = 0;
		}
		CHECK_EQUAL(0, TaskModelInternalTester::GetAllocationMapCount());
	}
Ejemplo n.º 17
0
TimeEntry * PlanEntryModelManager::GetEntryFromID(unsigned __int64 id)
{
	TimeEntry *pEntry = 0;
	StringBuffer conv(32);
	StringBuffer sb(_T("timeentry[@entryid='"));
	sb.append(ModelUtils::toHexString(id, conv));
	sb.append(_T("']"));
	BSTR xpath = SysAllocString(sb);
	MSXML2::IXMLDOMNode *pNode = 0;
	HRESULT hr = m_pRoot->selectSingleNode(xpath, &pNode);
	SysFreeString(xpath);
	if(hr == S_OK && pNode)
	{
		pEntry = new(pNode) PlanEntryModel(pNode);
		pNode->Release();
	}
	return pEntry;
}
Ejemplo n.º 18
0
MSXML2::IXMLDOMNode * RecurrenceManager::GetRecurrencesNode()
{
	MSXML2::IXMLDOMNode *pNode = 0;
	MSXML2::IXMLDOMElement *pRoot = 0;
	HRESULT hr = m_pXMLDoc->get_documentElement(&pRoot);
	BSTR xpath = SysAllocString(_T("//recurrences"));
	hr = m_pXMLDoc->selectSingleNode(xpath, reinterpret_cast<MSXML2::IXMLDOMNode **>(&pNode));
	SysFreeString(xpath);
	if(hr == S_FALSE)
	{
		MSXML2::IXMLDOMNode *pRootNode = 0;
		pRoot->QueryInterface(IID_IXMLDOMNode, reinterpret_cast<void **>(&pRootNode));
		XMLHelper::CreateChild(pRootNode, &pNode, _T("recurrences"));
		pRootNode->Release();
	}
	pRoot->Release();
	return pNode;
}
Ejemplo n.º 19
0
	void CXmlNodeWrapper::RemoveNodes(LPCTSTR searchStr)
	{
		if (!IsValid())
			return;
		MSXML2::IXMLDOMNodeListPtr nodeList = m_xmlnode->selectNodes(searchStr);
		for (int i = 0; i < nodeList->Getlength(); i++)
		{
			try
			{
				MSXML2::IXMLDOMNode* pNode = nodeList->Getitem(i).Detach();
				pNode->GetparentNode()->removeChild(pNode);
			}
			catch (_com_error er)
			{
				AfxMessageBox(er.ErrorMessage());
			}
		}
	}
Ejemplo n.º 20
0
		HRESULT XMLHelper::SetChildText(MSXML2::IXMLDOMNode *pNode, const TCHAR *pChild, const TCHAR *pText)
		{
			BSTR xpath = SysAllocString(pChild);
			MSXML2::IXMLDOMNode *pChildNode = 0;
			HRESULT hr = pNode->selectSingleNode(xpath, &pChildNode);
			SysFreeString(xpath);
			if(hr == S_OK && pChildNode) //replace existing text
			{
				BSTR text = SysAllocString(pText);
				hr = pChildNode->put_text(text);
				SysFreeString(text);
			}
			else if(hr == S_FALSE)  //if there is no node make a new one
			{
				hr = CreateChild(pNode, &pChildNode, pChild, pText);
				if(pChildNode)pChildNode->Release();
			}
			return hr;
		}
Ejemplo n.º 21
0
unsigned __int64 RecurrenceManager::FindTaskInstance(unsigned __int64 templateId, unsigned __int64 start)
{
	unsigned __int64 id = 0;
	StringBuffer conv(32);
	StringBuffer sb(_T("//task[@recurrenceid='"));
	sb.append(ModelUtils::toHexString(templateId, conv));
	sb.append(_T("' and @start='"));
	sb.append(ModelUtils::toHexString(start, conv));
	sb.append(_T("']"));
	BSTR xpath = SysAllocString(sb);
	MSXML2::IXMLDOMNode *pNode = 0;
	HRESULT hr = m_pXMLDoc->selectSingleNode(xpath, &pNode);
	if(hr == S_OK && pNode)
	{
		XMLHelper::GetAttributeI64(pNode, CTaskModel::TASKID, &id);
		pNode->Release();
	}
	SysFreeString(xpath);
	return id;
}
Ejemplo n.º 22
0
int CTaskModel::CheckPrerequisite(unsigned __int64 prereq)
{
	int result = 0;
	MSXML2::IXMLDOMNode *pNode = 0;
	StringBuffer sb(_T("//task[@taskid=\""));
	StringBuffer buf(32);
	sb.append(ModelUtils::toHexString(prereq, buf));
	sb.append(_T("\"]"));
	BSTR xpath = SysAllocString(sb);
	HRESULT hr = m_pNode->selectSingleNode(xpath, &pNode);
	SysFreeString(xpath);
	if(hr == S_OK && pNode)
	{
		CTaskModel task(pNode);
		if(task.IsComplete() || task.GetState() == TASK_STATE_COMPLETE)result = 1;
		else result = -1;
		pNode->Release();
	}
	return result;
}
Ejemplo n.º 23
0
// 获取当前结点的下一个Element兄弟结点
IBpXMLNode *CBpXMLNode::GetNextElementSibling() const
{
	if(m_pDOMNode == NULL)
		return NULL;

	MSXML2::IXMLDOMNode *pTempNode = m_pDOMNode;
	while (pTempNode != NULL)
	{
		pTempNode->get_nextSibling(&pTempNode);
		if (pTempNode == NULL)
			return NULL;

		if (pTempNode->GetnodeType() == MSXML2::NODE_ELEMENT)
		{
			CBpXMLNode *pNodeCreated  = new CBpXMLNode();	
			pNodeCreated->m_pDOMNode = pTempNode;
			return (IBpXMLNode*)pNodeCreated;
		}
	}
	return NULL;
}
Ejemplo n.º 24
0
void XmlParser::_parseNodeGetText(MSXML2::IXMLDOMNode *pIDOMNode, XmlNode& node)
{	
	MSXML2::IXMLDOMNode* ppFirstChild;
	BSTR bstrNodeType;

	pIDOMNode->get_firstChild(&ppFirstChild);
	
	if (ppFirstChild == NULL)
		return;
	
	ppFirstChild->get_nodeTypeString(&bstrNodeType);

	if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"text") == 0 ||
		(lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"cdatasection") == 0))
	{
		BSTR bstrItemText;

		ppFirstChild->get_text(&bstrItemText);
		node.SetText(wstring(bstrItemText));
	}
}
Ejemplo n.º 25
0
void CTaskModel::RemovePrerequisite(unsigned __int64 prereq)
{
	MSXML2::IXMLDOMNode *pNode = 0, *pOld = 0;
	StringBuffer sb(_T("prerequisite[@taskid=\""));
	StringBuffer buf(32);
	sb.append(ModelUtils::toHexString(prereq, buf));
	sb.append(_T("\"]"));
	BSTR xpath = SysAllocString(sb);
	HRESULT hr = m_pNode->selectSingleNode(xpath, &pNode);
	SysFreeString(xpath);
	if(hr == S_OK && pNode)
	{
		hr = m_pNode->removeChild(pNode, &pOld);
		if(hr == S_OK)
		{
			pOld->Release();
		}
		pNode->Release();
	}
	
	//TODO: notify?..
}
Ejemplo n.º 26
0
BOOL XMLPaser::ND_isThereTable( LPCTSTR strTable )
{
	MSXML2::IXMLDOMNode *pNode = NULL;
	BOOL bResult = FALSE;

	try
	{
		pNode = ND_pGetTableNode( strTable );

		if ( pNode )
			bResult = TRUE;
		else
			bResult = FALSE;

		pNode->Release();

		return ( bResult );
	}
	catch(...)
	{
		return ( FALSE );
	}
}
Ejemplo n.º 27
0
//checks for decendents, but for what purpose is the recurse?
bool CTaskModel::HasChild(unsigned __int64 id, bool recurse)
{
	StringBuffer sb;
	if(recurse)
	{
		sb.append(_T(".//"));
	}
	else
	{
		sb.append(_T("./"));
	}
	sb.append(_T("task[@taskid=\""));
	StringBuffer buf(32);
	sb.append(ModelUtils::toHexString(id, buf));
	sb.append(_T("\"]"));

	BSTR xpath = SysAllocString(sb);
	MSXML2::IXMLDOMNode *pNode = 0;
	HRESULT hr = m_pNode->selectSingleNode(xpath, &pNode);
	pNode->Release();
	SysFreeString(xpath);
	return (hr == S_OK);
}
Ejemplo n.º 28
0
HRESULT XMLPaser::ND_hrGetTableValue( LPCTSTR strTable, LPCTSTR strField, 
		UINT idxRow, TCHAR* pVal )
{
	HRESULT hr = E_FAIL;
	MSXML2::IXMLDOMNode *pNode = NULL;
	long idxColumn = -1;
	long lTableChilds = 0;
	long lfirstRow = 0;

	try
	{
		pNode = ND_pGetTableNode( strTable );

		if ( pNode )
		{
			MSXML2::IXMLDOMNodeList* pRowNodeList;
			pNode->get_childNodes( &pRowNodeList );

			if ( pRowNodeList )
			{
				pRowNodeList->get_length( &lTableChilds );

				MSXML2::IXMLDOMNode *pRowNode;
				BSTR bstrName;
				LPSTR pszName;

				for ( long ll = 0; ll < lTableChilds; ll++ )
				{
					pRowNodeList->get_item( ll, &pRowNode );
					pRowNode->get_baseName( &bstrName );

					// 처음 Row가 나오는 순간
					UnicodeToAnsi( bstrName, &pszName );
					if ( stricmp( pszName, _T("Row") ) == 0 )
					{
						lfirstRow = ll;
						CoTaskMemFree( pszName );
						::SysFreeString( bstrName );
						break;
					}

					CoTaskMemFree( pszName );
					::SysFreeString( bstrName );
				}

				if ( lfirstRow >= lTableChilds )
				{
					return ( E_FAIL );
				}

				pRowNodeList->get_item( lfirstRow, &pRowNode );

				if ( pRowNode )
				{
					MSXML2::IXMLDOMNodeList* pCellNodeList;
					pRowNode->get_childNodes( &pCellNodeList );

					if ( pCellNodeList )
					{
						long lCell = 0;
						pCellNodeList->get_length( &lCell );
						
						for ( long ll = 0; ll < lCell; ll++ )
						{
							MSXML2::IXMLDOMNode *pCellNode;
							pCellNodeList->get_item( ll, &pCellNode );

							if ( pCellNode )
							{
								MSXML2::IXMLDOMNode *pDataNode;
								pCellNode->get_firstChild( &pDataNode );
								if ( pDataNode )
								{
									LPSTR pszColumnName;
									pDataNode->get_text( &bstrName );
									UnicodeToAnsi( bstrName, &pszColumnName );

									if ( stricmp( pszColumnName, strField ) == 0 )
									{
										idxColumn = ll;
									}

									CoTaskMemFree( pszColumnName );
									::SysFreeString( bstrName );
									pDataNode->Release();
								}
								pCellNode->Release();
							}
						}
						pCellNodeList->Release();
					}
					pRowNode->Release();
				}

				pRowNodeList->get_item( idxRow + lfirstRow + 1, &pRowNode );

				if ( pRowNode )
				{
					MSXML2::IXMLDOMNodeList* pCellNodeList;
					pRowNode->get_childNodes( &pCellNodeList );

					if ( pCellNodeList )
					{
						MSXML2::IXMLDOMNode *pDataNode;
						pCellNodeList->get_item( idxColumn, &pDataNode );

						if ( pDataNode )
						{
							BSTR bstrData;
							LPSTR pszData;
							pDataNode->get_text( &bstrData );
							UnicodeToAnsi( bstrData, &pszData );

							strcpy( pVal, pszData );
							hr = S_OK;

							CoTaskMemFree( pszData );
							::SysFreeString( bstrData );
							pDataNode->Release();
						}
						pCellNodeList->Release();
					}
					pRowNode->Release();
				}
				pRowNodeList->Release();
			}
			pNode->Release();
		}

		return ( hr );
	}
	catch(...)
	{
		return ( E_FAIL );
	}
}
Ejemplo n.º 29
0
void XMLDOMParsingNodes(char *szFileName)
{

   try 
   {
	   //Qualify namespase explicitly to avoid Compiler Error C2872 "ambiguous symbol" during linking.
	   //Now Msxml2.dll use the "MSXML2" namespace
	   //(see http://support.microsoft.com/default.aspx?scid=kb;en-us;316317):
	   MSXML2::IXMLDOMDocumentPtr docPtr;//pointer to DOMDocument object
	   MSXML2::IXMLDOMNodeListPtr NodeListPtr;//indexed access. and iteration through the collection of nodes
	   MSXML2::IXMLDOMNodePtr DOMNodePtr;//pointer to the node

	   MSXML2::IXMLDOMNode *pIDOMNode = NULL;//pointer to element's node
	   MSXML2::IXMLDOMNode *pIParentNode = NULL;//pointer to parent node
	   MSXML2::IXMLDOMNode *pIAttrNode = NULL;//pointer to attribute node
	   MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr;//iteration through the collection of attribute nodes
	   MSXML2::IXMLDOMNodeList *childList=NULL;//node list containing the child nodes
	  
	 
	  //Variable with the name of node to find: 
	  BSTR strFindText  = L" ";//" " means to output every node

	  //Variables to store item's name, parent, text and node type:
	  BSTR bstrItemText,bstrItemNode, bstrItemParent,bstrNodeType;

	 //Variables to store attribute's name,type and text:	 
	  BSTR bstrAttrName, bstrAttrType, bstrAttrText;

	  HRESULT hResult;
	  
	  int i = 0;//loop-index variable
	  int n = 0;//lines counter
      

	  //Initialize COM Library:
      CoInitialize(NULL);

	 //Create an instance of the DOMDocument object:
      docPtr.CreateInstance(__uuidof(DOMDocument30));
		
      // Load a document:
	  _variant_t varXml(szFileName);//XML file to load
      _variant_t varResult((bool)TRUE);//result 
      
	  varResult = docPtr->load(varXml);

      if ((bool)varResult == FALSE)
	  {
		 //printf("*** Error:failed to load XML file. ***\n");
		 MessageBox(0,"Error: failed to load XML file. Check the file name.", \
			 "Load XML file",MB_OK |MB_ICONWARNING);
         return;
	  }

	  //Collect all or selected nodes by tag name:
	  NodeListPtr = docPtr->getElementsByTagName(strFindText);
  
	  //Output the number of nodes:
	  //printf("Number of nodes: %d\n", (NodeListPtr->length));

	  //Output root node:
	  docPtr->documentElement->get_nodeName(&bstrItemText);
	  //%ls formatting is for wchar_t* parameter's type (%s for char* type):
	  printf("\nRoot: %ls\n", bstrItemText);	
	  

	  for(i = 0; i < (NodeListPtr->length); i++)
	  {
		
			if (pIDOMNode) pIDOMNode->Release();			
			NodeListPtr->get_item(i, &pIDOMNode);
			
			
			if(pIDOMNode )
			{				
					
				pIDOMNode->get_nodeTypeString(&bstrNodeType);
				
				//We process only elements (nodes of "element" type): 
				BSTR temp = L"element";
			
				if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)temp)==0) 
				{
					n++;//element node's number
					printf("\n\n%d\n", n);//element node's number
					printf("Type: %ls\n", bstrNodeType);

					pIDOMNode->get_nodeName(&bstrItemNode);
					printf("Node: %ls\n", bstrItemNode);				
								 
					pIDOMNode->get_text(&bstrItemText);
					printf("Text: %ls\n", bstrItemText);
					
					pIDOMNode->get_parentNode(&pIParentNode);
					pIParentNode->get_nodeName(&bstrItemParent);
					printf("Parent: %ls\n",bstrItemParent);
					
			
					pIDOMNode->get_childNodes(&childList);
					printf("Child nodes: %d\n", (childList->length));
					
					//Get the attributes:
					int j = 0;//loop-index variable
					long length;// number of attributes in the collection

					DOMNamedNodeMapPtr = pIDOMNode->attributes;
				
					hResult = DOMNamedNodeMapPtr->get_length(&length);
	
					if(SUCCEEDED(hResult))
					{
					//Loop through the number of attributes:
						for(j = 0; j < length; j++)
						{														
							//get attribute node:							
							DOMNamedNodeMapPtr->get_item(j,&pIAttrNode);

							pIAttrNode->get_nodeTypeString(&bstrAttrType);//type as string
							printf("\nAttribute type: %ls\n", bstrAttrType);
							//pIAttrNode->get_nodeType(&bstrAttrType);//enumerated type
							//printf("Attribute type: %d\n", bstrAttrType);
							pIAttrNode->get_nodeName(&bstrAttrName);
							printf("Attribute name: %ls\n", bstrAttrName);
							pIAttrNode->get_text(&bstrAttrText);
							printf("Attribute value: %ls\n", bstrAttrText);						
						
						}
					}					
				//	::MessageBox(NULL, (LPCSTR) bstrItemText,"parsing", MB_OK);		
				}
			}
		}
	//Do not forget to release interfaces:
	pIDOMNode->Release();
	pIDOMNode = NULL;
	pIParentNode->Release();
	pIParentNode = NULL;
		
   } 

   catch(...)
   {
	  MessageBox(NULL, ("*** Exception occurred ***"), ("Error message"), MB_OK);
   }


    CoUninitialize();

}
Ejemplo n.º 30
0
void RecurrenceManager::RealizeRecurrence(MSXML2::IXMLDOMNode *pNode, SYSTEMTIME date)
{
	MSXML2::IXMLDOMNode *pScheduleNode = 0;
	BSTR xpath = SysAllocString(_T("schedule"));
	HRESULT hr = pNode->selectSingleNode(xpath, &pScheduleNode);
	if(hr == S_OK && pScheduleNode)
	{
		BSTR attribute = 0;
		hr = XMLHelper::GetAttribute(pScheduleNode, _T("starthour"), &attribute);
		if(hr == S_OK && attribute)
		{
			date.wHour = _wtoi(attribute);

			SysFreeString(attribute);
			attribute = 0;

			hr = XMLHelper::GetAttribute(pScheduleNode, _T("startminute"), &attribute);
			if(hr == S_OK && attribute)
			{
				date.wMinute = _wtoi(attribute);

				SysFreeString(attribute);
				attribute = 0;

				hr = XMLHelper::GetAttribute(pScheduleNode, _T("duration"), &attribute);
				if(hr == S_OK && attribute)
				{
					int duration = _wtoi(attribute);
					
					SysFreeString(attribute);
					attribute = 0;
				
					unsigned __int64 start = ModelUtils::SystemTimeToI64(date);

					unsigned __int64 templateId = 0;	
					HRESULT hr = XMLHelper::GetAttributeI64(pNode, _T("recurrenceid"), &templateId);
					if(hr == S_OK)
					{
						unsigned __int64 parentId = 0;	
						HRESULT hr = XMLHelper::GetAttributeI64(pNode, _T("parentid"), &parentId);
						if(hr == S_OK)
						{

							hr = XMLHelper::GetAttribute(pNode, _T("type"), 	&attribute);
							if(hr == S_OK && attribute)
							{
								if(!_tcscmp(_T("task"), attribute))
								{
									RealizeTask(pNode, templateId, parentId, start, duration);
								}
								//else if(!_tcscmp(_T("event"), attribute))
								//{
								//	RealizeEvent(pNode, templateId, parentId, start, duration);
								//}
								SysFreeString(attribute);
							}
						}
					}
				}
			}
		}
		pScheduleNode->Release();
	}
	SysFreeString(xpath);
}