当前位置: 首页>>代码示例>>C++>>正文


C++ IXMLDOMNodePtr::insertBefore方法代码示例

本文整理汇总了C++中msxml2::IXMLDOMNodePtr::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMNodePtr::insertBefore方法的具体用法?C++ IXMLDOMNodePtr::insertBefore怎么用?C++ IXMLDOMNodePtr::insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msxml2::IXMLDOMNodePtr的用法示例。


在下文中一共展示了IXMLDOMNodePtr::insertBefore方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InsertEnterAndTabs

MSXML2::IXMLDOMNodePtr CXmlBase::InsertEnterAndTabs(MSXML2::IXMLDOMNodePtr pParentNode, MSXML2::IXMLDOMNodePtr pNode, 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;

	if(pNode == NULL)nLevel = 0;

	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;
		CComVariant varNode = pNode.GetInterfacePtr();
		pTabsNode = pParentNode->insertBefore(pTabsText, varNode);


		//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;
}
开发者ID:cugxiangzhenwei,项目名称:WorkPlatForm,代码行数:56,代码来源:XmlBase.cpp

示例2: Build

////////////////////////////////////////////////////////////////////////////
// Function: Create an XML DOM Document from Scratch in memory
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::Build()
{
	// Create a root node
	MSXML2::IXMLDOMNodePtr pRoot;
	m_pDoc->createNode(CComVariant(MSXML2::NODE_ELEMENT), CComBSTR("Root"), NULL, &pRoot);

	// add child nodes
	HRESULT hr = S_OK;
	for (int i = 0; i < 10; i++)
	{
		MSXML2::IXMLDOMNodePtr pNode;
		m_pDoc->createNode(CComVariant(MSXML2::NODE_ELEMENT), CComBSTR("Order"), NULL, &pNode);

		MSXML2::IXMLDOMElementPtr pElement = pNode;
		if (pElement != NULL)
			pElement->setAttribute(CComBSTR("id"), CComVariant(i));

		MSXML2::IXMLDOMNodePtr p0 = NULL;
		CComVariant after;
		hr = pRoot->insertBefore(pNode, after, &p0);
		hr = CheckHR(hr, "inserting node");

		// The XML Document should now own the node.
		for (int j = 0; j < 10; j++)
		{
			MSXML2::IXMLDOMNodePtr pNode2;
			m_pDoc->createNode(CComVariant(MSXML2::NODE_ELEMENT), CComBSTR("Item"), NULL, &pNode2);

			MSXML2::IXMLDOMElementPtr pElement2 = pNode2;
			if (pElement2 != NULL)
				pElement2->setAttribute(CComBSTR("id"), CComVariant((i*10) + j));
	
			MSXML2::IXMLDOMNodePtr p1 = NULL;
			CComVariant after;
			hr = p0->insertBefore(pNode2, after, &p1);
			hr = CheckHR(hr, "inserting node");
			// The XML Document should now own the node.
		}
	}

	// Now attach this new subtree to the document.
	m_pDoc->appendChild(pRoot, NULL);

	return hr;
}
开发者ID:jimmccurdy,项目名称:ArchiveGit,代码行数:48,代码来源:CXMLDocument.cpp

示例3: InsertNode

MSXML2::IXMLDOMNodePtr CXmlBase::InsertNode( MSXML2::IXMLDOMNodePtr pParentNode , MSXML2::IXMLDOMNodePtr pNodeBack , 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;
		CComVariant varNode = pNodeBack.GetInterfacePtr();
		pNode = pParentNode->insertBefore(pNode, varNode);
	}
	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;
}
开发者ID:cugxiangzhenwei,项目名称:WorkPlatForm,代码行数:39,代码来源:XmlBase.cpp


注:本文中的msxml2::IXMLDOMNodePtr::insertBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。