本文整理汇总了C++中IXMLDOMDocument::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument::QueryInterface方法的具体用法?C++ IXMLDOMDocument::QueryInterface怎么用?C++ IXMLDOMDocument::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMDocument
的用法示例。
在下文中一共展示了IXMLDOMDocument::QueryInterface方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: LoadDB
//--------------------------------------------------------------------------------------
HRESULT CRatingsDB::LoadDB()
{
// Find resource will pick the right ID_GDF_XML_STR based on the current language
HRSRC hrsrc = FindResource( nullptr, MAKEINTRESOURCE(ID_RATINGS_XML), L"DATA" );
if( hrsrc )
{
HGLOBAL hgResource = LoadResource( nullptr, hrsrc );
if( hgResource )
{
BYTE* pResourceBuffer = (BYTE*)LockResource( hgResource );
if( pResourceBuffer )
{
DWORD dwGDFXMLSize = SizeofResource( nullptr, hrsrc );
if( dwGDFXMLSize )
{
// HGLOBAL from LoadResource() needs to be copied for CreateStreamOnHGlobal() to work
HGLOBAL hgResourceCopy = GlobalAlloc( GMEM_MOVEABLE, dwGDFXMLSize );
if( hgResourceCopy )
{
LPVOID pCopy = GlobalLock( hgResourceCopy );
if( pCopy )
{
CopyMemory( pCopy, pResourceBuffer, dwGDFXMLSize );
GlobalUnlock( hgResource );
IStream* piStream = nullptr;
HRESULT hr = CreateStreamOnHGlobal( hgResourceCopy, TRUE, &piStream );
if( SUCCEEDED(hr) && piStream )
{
IXMLDOMDocument *pDoc = nullptr;
// Load the XML into a IXMLDOMDocument object
hr = CoCreateInstance( CLSID_DOMDocument, nullptr, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, (void**)&pDoc );
if( SUCCEEDED(hr) )
{
IPersistStreamInit* pPersistStreamInit = nullptr;
hr = pDoc->QueryInterface( IID_IPersistStreamInit, (void**) &pPersistStreamInit );
if( SUCCEEDED(hr) )
{
hr = pPersistStreamInit->Load( piStream );
if( SUCCEEDED(hr) )
{
// Get the root node to the XML doc and store it
pDoc->QueryInterface( IID_IXMLDOMNode, (void**)&m_pRootNode );
}
SAFE_RELEASE( pPersistStreamInit );
}
SAFE_RELEASE( pDoc );
}
SAFE_RELEASE( piStream );
}
}
GlobalFree( hgResourceCopy );
}
}
}
}
}
if( m_pRootNode )
return S_OK;
else
return E_FAIL;
}
示例3: XMLToScanParam
///////////////////////////////////////////////////////////////
// 功能: XML 文档文本转换成扫描参数结构
// 参数: sXMLDocText [in] XML文档的文本
// sp [out] 扫描参数结构
// 返回: true - 成功, false - 失败
bool ScanParamXML::XMLToScanParam( const string &sXMLDocText, ScanParameter &sp )
{
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;
}
VARIANT_BOOL bOk;
_variant_t varSrc = sXMLDocText.c_str();
IXMLDOMElement *pRootNode; // 根结点
IXMLDOMNode *pNode;
IXMLDOMNode *pNodeOut;
pXmlDoc->loadXML( varSrc.bstrVal, &bOk ); // 从字符串建立XML文档
// 取得根结点
pXmlDoc->get_documentElement( &pRootNode );
pRootNode->get_nodeName( &varSrc.bstrVal );
// 遍历根结点的子结点
for( pRootNode->get_firstChild( &pNode );
pNode != NULL; pNode->get_nextSibling( &pNode ) )
{
pNode->get_nodeName( &varSrc.bstrVal );
// cout << "Node name: " << varSrc.operator _bstr_t().operator char *() << endl;
string sNodeName = _bstr_t( varSrc.bstrVal ).operator char *();
if( sNodeName == string( "Depth" ) )
{ // 发现 Depth 结点
varSrc = ReadNodeText( pNode );
sp.nDepth = atoi( _bstr_t( varSrc.bstrVal ).operator char *() );
//cout << "Depth value: " << sp.nDepth << endl;
}
else if( sNodeName == string( "TryTimes" ) )
{ // 发现 TryTimes 结点
varSrc = ReadNodeText( pNode );
sp.nTryTimes = atoi( _bstr_t( varSrc.bstrVal ).operator char *() );
//cout << "TryTimes value: " << sp.nTryTimes << endl;
}
else if( sNodeName == string( "Timeout" ) )
{ // 发现 Timeout 结点
varSrc = ReadNodeText( pNode );
sp.nTimeout = atoi( _bstr_t( varSrc.bstrVal ).operator char *() );
//cout << "Timeout value: " << sp.nTimeout << endl;
}
else if( sNodeName == string( "MaxTreadCount" ) )
{ // 发现 MaxTreadCount 结点
varSrc = ReadNodeText( pNode );
sp.nMaxTreadCount = atoi( _bstr_t( varSrc.bstrVal ).operator char *() );
//cout << "MaxTreadCount value: " << sp.nMaxTreadCount << endl;
}
else if( sNodeName == string( "SubScan" ) )
{ // 发现 SubScan 结点
varSrc = ReadNodeText( pNode );
sp.bSubScan = ( string( _bstr_t( varSrc.bstrVal ).operator char *() ) == XML_TRUE ) ;
//cout << "SubScan value: " << sp.bSubScan << endl;
}
else if( sNodeName == string( "DefaultCommunityGet" ) )
{ // 发现 DefaultCommunityGet 结点
varSrc = ReadNodeText( pNode );
sp.sDefaultCommunityOfGet = _bstr_t( varSrc.bstrVal ).operator char *();
//cout << "DefaultCommunityGet value: " << sp.sDefaultCommunityOfGet << endl;
}
else if( sNodeName == string( "DefaultCommunitySet" ) )
{ // 发现 DefaultCommunitySet 结点
varSrc = ReadNodeText( pNode );
sp.sDefaultCommunityOfSet = _bstr_t( varSrc.bstrVal ).operator char *();
//cout << "DefaultCommunityOfSet value: " << sp.sDefaultCommunityOfSet << endl;
}
//.........这里部分代码省略.........