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


C++ IXMLDOMDocument::get_xml方法代码示例

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


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

示例1: dynamDOM

void dynamDOM()
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMElement *pRoot = NULL;
    IXMLDOMElement *pNode = NULL;
    IXMLDOMElement *pSubNode = NULL;
    IXMLDOMDocumentFragment *pDF = NULL;

    BSTR bstrXML = NULL;
    VARIANT varFileName;
    VariantInit(&varFileName);

    CHK_HR(CreateAndInitDOM(&pXMLDom));

    // Create a processing instruction element.
    CHK_HR(CreateAndAddPINode(pXMLDom, L"xml", L"version='1.0'"));

    // Create a comment element.
    CHK_HR(CreateAndAddCommentNode(pXMLDom, L"sample xml file created using XML DOM object."));

    // Create the root element.
    CHK_HR(CreateElement(pXMLDom, L"root", &pRoot));

    // Create an attribute for the <root> element, with name "created" and value "using dom".
    CHK_HR(CreateAndAddAttributeNode(pXMLDom, L"created", L"using dom", pRoot));

    // Next, we will create and add three nodes to the <root> element.
    // Create a <node1> to hold text content.
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"node1", L"\n\t", pRoot, &pNode));
    CHK_HR(CreateAndAddTextNode(pXMLDom, L"some character data", pNode));
    SAFE_RELEASE(pNode);

    // Create a <node2> to hold a CDATA section.
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"node2", L"\n\t", pRoot, &pNode));
    CHK_HR(CreateAndAddCDATANode(pXMLDom, L"<some mark-up text>", pNode));
    SAFE_RELEASE(pNode);

    // Create <node3> to hold a doc fragment with three sub-elements.
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"node3", L"\n\t", pRoot, &pNode));

    // Create a document fragment to hold three sub-elements.
    CHK_HR(pXMLDom->createDocumentFragment(&pDF));

    // Create 3 subnodes.
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode1", L"\n\t\t", pDF));
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode2", L"\n\t\t", pDF));
    CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode3", L"\n\t\t", pDF));
    CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n\t", pDF));

    // Append pDF to <node3>.
    CHK_HR(AppendChildToParent(pDF, pNode));
    SAFE_RELEASE(pNode);

    // Add NEWLINE for identation before </root>.
    CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n", pRoot));
    // add <root> to document
    CHK_HR(AppendChildToParent(pRoot, pXMLDom));

    CHK_HR(pXMLDom->get_xml(&bstrXML));
    wprintf(L"Dynamically created DOM:\n%s\n", bstrXML);

    CHK_HR(VariantFromString(L"dynamDOM.xml", varFileName));
    CHK_HR(pXMLDom->save(varFileName));
    wprintf(L"DOM saved to dynamDOM.xml\n");

CleanUp:
    SAFE_RELEASE(pXMLDom);
    SAFE_RELEASE(pRoot);
    SAFE_RELEASE(pNode);
    SAFE_RELEASE(pDF);
    SAFE_RELEASE(pSubNode);
    SysFreeString(bstrXML);
    VariantClear(&varFileName);
}
开发者ID:DMFZ,项目名称:Windows-classic-samples,代码行数:75,代码来源:dynamDOM.cpp

示例2: ScanParamToXML


//.........这里部分代码省略.........
			for( VectorOfCommunity::iterator it = vComm.begin();
				pNodeOut != NULL && it != vComm.end(); it++ )
			{
				IXMLDOMNode *pNodeCommunity = AddChildElem( pNodeOut, pXmlDoc, "Community" );

				_variant_t varNodeVal = it->sStartIp.c_str();
				AddChildNodeWithValue( pNodeCommunity, pXmlDoc, "StartIp", varNodeVal );
				varNodeVal = it->sEndIp.c_str();
				AddChildNodeWithValue( pNodeCommunity, pXmlDoc, "EndIp", varNodeVal );
				varNodeVal = it->sGet.c_str();
				AddChildNodeWithValue( pNodeCommunity, pXmlDoc, "Get", varNodeVal );
				varNodeVal = it->sSet.c_str();
				AddChildNodeWithValue( pNodeCommunity, pXmlDoc, "Set", varNodeVal );
			}
		}

		// IpScopeList 向量操作
		if( sp.viIpScopeList.size() > 0 )
		{
			VectorOfIpScope &vIpScope = const_cast< VectorOfIpScope & >( sp.viIpScopeList );
			pNodeOut = AddChildElem( pRootNode, pXmlDoc, "AddStartEnds" );
			for( VectorOfIpScope::iterator it = vIpScope.begin();
				pNodeOut != NULL && it != vIpScope.end(); it++ )
			{
				IXMLDOMNode *pNodeIpScope = AddChildElem( pNodeOut, pXmlDoc, "AddStartEnd" );

				_variant_t varNodeVal = it->sIpBegin.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "StartIp", varNodeVal );
				varNodeVal = it->sIpEnd.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "EndIp", varNodeVal );
			}
		}

		// FilterStartEndList 向量操作
		if( sp.viFilterStartEndList.size() > 0 )
		{
			VectorOfIpScope &vIpScope = const_cast< VectorOfIpScope & >( sp.viFilterStartEndList );
			pNodeOut = AddChildElem( pRootNode, pXmlDoc, "FilterStartEnds" );
			for( VectorOfIpScope::iterator it = vIpScope.begin();
				pNodeOut != NULL && it != vIpScope.end(); it++ )
			{
				IXMLDOMNode *pNodeIpScope = AddChildElem( pNodeOut, pXmlDoc, "FilterStartEnd" );

				_variant_t varNodeVal = it->sIpBegin.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "StartIp", varNodeVal );
				varNodeVal = it->sIpEnd.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "EndIp", varNodeVal );
			}
		}		

		// SubnetList 向量操作
		if( sp.viSubnetList.size() > 0 )
		{
			VectorOfIpScope &vIpScope = const_cast< VectorOfIpScope & >( sp.viSubnetList );
			pNodeOut = AddChildElem( pRootNode, pXmlDoc, "SubnetList" );
			for( VectorOfIpScope::iterator it = vIpScope.begin();
				pNodeOut != NULL && it != vIpScope.end(); it++ )
			{
				IXMLDOMNode *pNodeIpScope = AddChildElem( pNodeOut, pXmlDoc, "Subnet" );

				_variant_t varNodeVal = it->sIpBegin.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "StartIp", varNodeVal );
				varNodeVal = it->sIpEnd.c_str();
				AddChildNodeWithValue( pNodeIpScope, pXmlDoc, "EndIp", varNodeVal );
			}
		}

		// SeedIpList 向量操作
		if( sp.vsSeedIpList.size() > 0 )
		{
			VectorOfString &vIpSeed = const_cast< VectorOfString & >( sp.vsSeedIpList );
			pNodeOut = AddChildElem( pRootNode, pXmlDoc, "SeedIpList" );
			for( VectorOfString::iterator it = vIpSeed.begin();
				pNodeOut != NULL && it != vIpSeed.end(); it++ )
			{
				_variant_t varNodeVal = (*it).c_str();
				AddChildNodeWithValue( pNodeOut, pXmlDoc, "Seed", varNodeVal );				
			}
		}

		// 处理输出参数
		BSTR bstrXml;
		pXmlDoc->get_xml( &bstrXml );
		bstrName = bstrXml;

		sXMLDocText = bstrName.operator char *();

		SysFreeString( bstrXml );

		// 保存到文件(用于测试)
		// _variant_t varString = _T("C:\\sample.xml");
		// pXmlDoc->save( varString );
	} 
	catch(...)
	{
		return false;
	}

	return true;
}
开发者ID:,项目名称:,代码行数:101,代码来源:


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