Esempio n. 1
0
MSXML2::IXMLDOMDocument2Ptr CXmlBase::GetXmlDocPtrByFile(LPCTSTR lpszXmlPathFile
	, LPCTSTR lpszNamespace)
{
	CComBSTR bstrXml;
	CString str(_T(""));
	HRESULT hr = S_OK;
	MSXML2::IXMLDOMDocument2Ptr pDoc;

	//载入到xml文档结构中
	hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
	if (FAILED(hr))
	{
//		WRITELOG("END, FAILED TO INVOKE pDoc.CreateInstance");
		return NULL;
	}

	pDoc->async = VARIANT_TRUE; //加载方式为“同步”
	pDoc->validateOnParse = VARIANT_FALSE; //文档结构有错误时,停止解析。

	if (VARIANT_FALSE == pDoc->load(lpszXmlPathFile))
	{
		//WRITELOG("END, FAILED TO INVOKE pDoc->load(%s)", strXmlPathFile);
		return NULL;
	}

	if (lpszNamespace != NULL)
	{
		hr = pDoc->setProperty("SelectionLanguage", "XPath");
		if (FAILED(hr)) return NULL;
		hr = pDoc->setProperty("SelectionNamespaces", lpszNamespace);
		if (FAILED(hr)) return NULL;
	}

	return pDoc;
}
Esempio n. 2
0
BOOL CXmlBase::SetNameSpace(MSXML2::IXMLDOMDocument2Ptr& pDoc, LPCTSTR lpszNameSpace)
{
	HRESULT hr = S_OK;
	if (lpszNameSpace == NULL 
		|| pDoc == NULL) return FALSE;
	
	hr = pDoc->setProperty("SelectionLanguage", "XPath");
	if (FAILED(hr)) return FALSE;
	hr = pDoc->setProperty("SelectionNamespaces", lpszNameSpace);
	if (FAILED(hr)) return FALSE;
	return TRUE;
}
Esempio n. 3
0
	MSXML2::IXMLDOMDocument2Ptr setupXMLParser(char *path)
	{
		HRESULT hr;
		MSXML2::IXMLDOMDocument2Ptr xmlDoc;
		
		hr = CoInitialize(NULL);
		hr = xmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
		if (FAILED(hr)) return NULL;

		if (xmlDoc->load(path) != VARIANT_TRUE) return NULL;

		hr = xmlDoc->setProperty("SelectionNamespaces", "xmlns:r='http://www.collada.org/2005/11/COLLADASchema'");
		hr = xmlDoc->setProperty("SelectionLanguage", "XPath");

		return xmlDoc;
	}
Esempio n. 4
0
bool Engine::LoadContent()
{
	// Setup our SpriteBatch.
	m_pSpriteBatch = new DirectX::SpriteBatch(d3dContext_);

	m_pFont->Initialize(d3dDevice_, std::wstring(L"Calibri18.spritefont"));
	m_pSprite->Initialize(d3dDevice_, std::wstring(L"Test.dds"), 10.0f, 10.0f); 
	
	m_textToDisplay = Text();
	m_textToDisplay.Initialize(std::wstring(L"Sarah"), DirectX::SimpleMath::Vector2(200.0f, 200.0f));

	try
	{
		MSXML2::IXMLDOMDocument2Ptr xmlDoc;
		HRESULT hr = xmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);

		teamStats.InitializeTeam("Players.xml");

		// Make sure the file was loaded correctly before trying to load the players.
		if (xmlDoc->load("Players.xml") == VARIANT_TRUE)
		{
			//xmlDoc->setProperty("SelectionLanguage", "XPath");
			//teamStats.LoadPlayers(xmlDoc);
		}


		if (xmlDoc->load("input.xml") != VARIANT_TRUE)
		{
			DXTRACE_MSG("Unable to load input.xml\n");

			xmlDoc->save("input.xml");
			//xmlDoc->
		}
		else
		{
			DXTRACE_MSG("XML was successfully loaded \n");

			xmlDoc->setProperty("SelectionLanguage", "XPath");
			MSXML2::IXMLDOMNodeListPtr wheels = xmlDoc->selectNodes("/Car/Wheels/*");
			DXTRACE_MSG("Car has %u wheels\n", wheels->Getlength());
		
			DXTRACE_MSG(wheels->Getitem(0)->text);

			//ptr->

			MSXML2::IXMLDOMNodePtr node;
			node = xmlDoc->createNode(MSXML2::NODE_ELEMENT, ("Engine"), (""));
			node->text = ("Engine 1.0");
			xmlDoc->documentElement->appendChild(node);
			hr = xmlDoc->save("output.xml");

			if (SUCCEEDED(hr))
			{
				DXTRACE_MSG("output.xml successfully saved\n");
			}
		}
	}
	catch (_com_error &e)
	{
		DXTRACE_MSG(e.ErrorMessage());
	}










	return true;
}