本文整理汇总了C++中IXMLDOMDocument::appendChild方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument::appendChild方法的具体用法?C++ IXMLDOMDocument::appendChild怎么用?C++ IXMLDOMDocument::appendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMDocument
的用法示例。
在下文中一共展示了IXMLDOMDocument::appendChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ScanParamToXML
///////////////////////////////////////////////////////////////
// 功能: 扫描参数结构转换成 XML 文档
// 参数: sp [in] 扫描参数结构
// sXMLDocText [out] XML文档的文本
// 返回: true - 成功, false - 失败
bool ScanParamXML::ScanParamToXML( const ScanParameter &sp, string &sXMLDocText )
{
try
{
IXMLDOMDocument *pXmlDoc = NULL;
IXMLDOMNode *pXmlDomNode = NULL;
// 得到关于IXMLDOMDocument 接口的指针 pXMLDOC
HRESULT hr = ::CoCreateInstance( CLSID_DOMDocument,
NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument,
( void ** )&pXmlDoc );
if( S_OK != hr )
{
return false;
}
//得到关于IXMLDOMNode接口的指针pXDN
hr = pXmlDoc->QueryInterface( IID_IXMLDOMNode,
( void ** )&pXmlDomNode );
if( S_OK != hr )
{
return false;
}
IXMLDOMNode *pNode;
IXMLDOMNode *pNodeOut;
IXMLDOMNode *pRootNode;
_variant_t varNodeType = NODE_ELEMENT;
_variant_t varNodeVal;
_bstr_t bstrName;
_bstr_t bstrDataType = NODE_CDATA_SECTION ;
// 创建根结点
bstrName = _T("TopDiscoverParas");
hr = pXmlDoc->createNode( varNodeType , bstrName, 0, &pNode );
pXmlDoc->appendChild( pNode, &pRootNode );
// 创建Depth结点
varNodeVal = sp.nDepth;
AddChildNodeWithValue( pRootNode, pXmlDoc, "Depth", varNodeVal );
// 创建Tineout结点
varNodeVal = sp.nTimeout;
AddChildNodeWithValue( pRootNode, pXmlDoc, "Timeout", varNodeVal );
// 创建TryTimes结点
varNodeVal = sp.nTryTimes;
AddChildNodeWithValue( pRootNode, pXmlDoc, "TryTimes", varNodeVal );
// 创建SubScan结点
varNodeVal = sp.bSubScan ? XML_TRUE : XML_FALSE;
AddChildNodeWithValue( pRootNode, pXmlDoc, "SubScan", varNodeVal );
// 创建MaxTreadCount结点
varNodeVal = sp.nMaxTreadCount;
AddChildNodeWithValue( pRootNode, pXmlDoc, "MaxTreadCount", varNodeVal );
// 创建DefaultCommunityGet结点
varNodeVal = sp.sDefaultCommunityOfGet.c_str();
AddChildNodeWithValue( pRootNode, pXmlDoc, "DefaultCommunityGet", varNodeVal );
// 创建DefaultCommunitySet结点
varNodeVal = sp.sDefaultCommunityOfSet.c_str();
AddChildNodeWithValue( pRootNode, pXmlDoc, "DefaultCommunitySet", varNodeVal );
// CommunityList 向量操作
if( sp.vcCommunityList.size() > 0 )
{
VectorOfCommunity &vComm = const_cast< VectorOfCommunity & >( sp.vcCommunityList );
pNodeOut = AddChildElem( pRootNode, pXmlDoc, "Communitys" );
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 )
{
//.........这里部分代码省略.........
示例2: XmlCreateDocument
/********************************************************************
XmlCreateDocument -
*********************************************************************/
extern "C" HRESULT DAPI XmlCreateDocument(
__in_opt LPCWSTR pwzElementName,
__out IXMLDOMDocument** ppixdDocument,
__out_opt IXMLDOMElement** ppixeRootElement
)
{
HRESULT hr = S_OK;
BOOL (WINAPI *pfnDisableWow64)(__out PVOID* ) = NULL;
BOOL (WINAPI *pfnEnableWow64)(__in BOOLEAN ) = NULL;
BOOL (WINAPI *pfnRevertWow64)(__in PVOID ) = NULL;
BOOL fWow64Available = FALSE;
void *pvWow64State = NULL;
// RELEASEME
IXMLDOMElement* pixeRootElement = NULL;
IXMLDOMDocument *pixdDocument = NULL;
// Test if we have access to the Wow64 API, and store the result in fWow64Available
HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll");
ExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll");
// This will test if we have access to the Wow64 API
if (NULL != GetProcAddress(hKernel32, "IsWow64Process"))
{
pfnDisableWow64 = (BOOL (WINAPI *)(PVOID *))::GetProcAddress(hKernel32, "Wow64DisableWow64FsRedirection");
pfnEnableWow64 = (BOOL (WINAPI *)(BOOLEAN))::GetProcAddress(hKernel32, "Wow64EnableWow64FsRedirection");
pfnRevertWow64 = (BOOL (WINAPI *)(PVOID))::GetProcAddress(hKernel32, "Wow64RevertWow64FsRedirection");
fWow64Available = pfnDisableWow64 && pfnEnableWow64 && pfnRevertWow64;
}
// create the top level XML document
AssertSz(vcXmlInitialized, "XmlInitialize() was not called");
// Enable Wow64 Redirection, if possible
if (fWow64Available)
{
// We want to enable Wow64 redirection, but the Wow64 API requires us to disable it first to get its current state (so we can revert it later)
pfnDisableWow64(&pvWow64State);
// If we fail to enable it, don't bother trying to disable it later on
fWow64Available = pfnEnableWow64(TRUE);
}
hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument);
ExitOnFailure(hr, "failed to create XML DOM Document");
Assert(pixdDocument);
if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20))
{
vfMsxml30 = TRUE;
}
if (pwzElementName)
{
hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement);
ExitOnFailure(hr, "failed XmlCreateElement");
hr = pixdDocument->appendChild(pixeRootElement, NULL);
ExitOnFailure(hr, "failed appendChild");
}
*ppixdDocument = pixdDocument;
pixdDocument = NULL;
if (ppixeRootElement)
{
*ppixeRootElement = pixeRootElement;
pixeRootElement = NULL;
}
LExit:
// Re-disable Wow64 Redirection, if appropriate
if (fWow64Available && !pfnRevertWow64(pvWow64State))
{
// If we expected to be able to revert, and couldn't, fail in the only graceful way we can
::ExitProcess(1);
}
ReleaseObject(pixeRootElement);
ReleaseObject(pixdDocument);
return hr;
}