本文整理汇总了C++中IXMLDOMNode::selectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMNode::selectSingleNode方法的具体用法?C++ IXMLDOMNode::selectSingleNode怎么用?C++ IXMLDOMNode::selectSingleNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMNode
的用法示例。
在下文中一共展示了IXMLDOMNode::selectSingleNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDescriptorName
//--------------------------------------------------------------------------------------
HRESULT CRatingsDB::GetDescriptorName( WCHAR* strRatingSystemGUID, WCHAR* strDescriptorGUID, WCHAR* strDest, int cchDest )
{
wcscpy_s( strDest, cchDest, strDescriptorGUID );
WCHAR strRatingSystemGUIDUpper[512];
wcscpy_s( strRatingSystemGUIDUpper, 512, strRatingSystemGUID );
_wcsupr_s( strRatingSystemGUIDUpper );
WCHAR strDescriptorGUIDUpper[512];
wcscpy_s( strDescriptorGUIDUpper, 512, strDescriptorGUID );
_wcsupr_s( strDescriptorGUIDUpper );
HRESULT hr;
IXMLDOMNode* pRatingSystemNode = nullptr;
WCHAR str[512];
swprintf_s( str, 512, L"//Ratings/RatingSystem[@ID='%s']", strRatingSystemGUIDUpper );
hr = m_pRootNode->selectSingleNode( str, &pRatingSystemNode );
if( SUCCEEDED(hr) && pRatingSystemNode )
{
IXMLDOMNode* pRatingIDNode = nullptr;
swprintf_s( str, 512, L"Descriptor[@ID='%s']", strDescriptorGUIDUpper );
hr = pRatingSystemNode->selectSingleNode( str, &pRatingIDNode );
if( SUCCEEDED(hr) && pRatingIDNode )
{
hr = GetAttribFromNode( pRatingIDNode, L"Text", strDest, cchDest );
SAFE_RELEASE( pRatingIDNode );
}
SAFE_RELEASE( pRatingSystemNode );
}
return hr;
}
示例2: GetNode
/*
Function name : CXML::GetNode
Description : This is a helper function which, gives the pointer to node.
: searching for node can be started either from the current node
: or it may be started from the Root Node depending on the value of
: bCurrentNodeAsBase.
Return type : bool
Argument : CString csPathToNode
Argument : LPCTSTR lpszAttribute
Argument : LPCTSTR lpszValue
Argument : bool bCurrentNodeAsBase
Tested : Ok
*/
bool CXML::GetNode(IXMLDOMNode ** pNode,CString &rcsPathToNode,LPCTSTR lpszAttribute,LPCTSTR lpszValue,bool bCurrentNodeAsBase )
{
IXMLDOMNode * pBaseNode = NULL;
CString csPath("");
if(bCurrentNodeAsBase)
{
if(!m_pICurrentNode)
return false;
pBaseNode = m_pICurrentNode;
if(lpszAttribute)
csPath.Format("./%s[@%s = \"%s\"]",rcsPathToNode,lpszAttribute,lpszValue);
else
csPath.Format("./%s",rcsPathToNode);
}
else
{
if(!m_pIRootNode)
return false;
pBaseNode = m_pIRootNode;
if(lpszAttribute)
csPath.Format("/%s[@%s = \"%s\"]",rcsPathToNode,lpszAttribute,lpszValue);
else
csPath.Format("/%s",rcsPathToNode);
}
pBaseNode->AddRef();
BSTR bsPathToNode = csPath.AllocSysString();
m_hr = pBaseNode->selectSingleNode(bsPathToNode,pNode);
SysFreeString(bsPathToNode);
pBaseNode ->Release();
if (!SUCCEEDED(m_hr) || !(*pNode))
return false;
return true;
}
示例3: GoToNodeEx
/*
Function name : CXML::GoToNode
Description : Moves to the node having the specified text
Return type : bool
Argument : CString csPathToNode
Argument : CString csNodeText
Argument : bool bCurrentNodeAsBase
Tested : Not working
*/
bool CXML::GoToNodeEx(CString csPathToNode,CString csNodeText,bool bCurrentNodeAsBase)
{
CString csPath;
IXMLDOMNode *pBaseNode = NULL;
if(bCurrentNodeAsBase)
{
if(!m_pICurrentNode) return false;
pBaseNode = m_pICurrentNode;
pBaseNode->AddRef();
csPath.Format("./%s[.= \"%s\"]",csPathToNode,csNodeText);
}
else
{
if(!m_pIRootNode) return false;
pBaseNode = m_pIRootNode;
pBaseNode->AddRef();
csPath.Format("/%s[.= \"%s\"]",csPathToNode,csNodeText);
}
BSTR bstrPath = csPath.AllocSysString();
IXMLDOMNode * pNode = NULL;
m_hr = pBaseNode->selectSingleNode(bstrPath,&pNode);
pBaseNode->Release();
SysFreeString(bstrPath);
if(!SUCCEEDED(m_hr) || !pNode)
return false;
if(m_pICurrentNode)
{
m_pICurrentNode->Release();
m_pICurrentNode = NULL;
}
m_pICurrentNode = pNode;
m_pICurrentNode->AddRef();
pNode->Release();
return true;
}
示例4: SetValueByPattern
HRESULT CKADmerge::SetValueByPattern(string sElementPattern,
string sAttributePattern,
string sValue,
string sLogFile)
{
HRESULT hRes = 0;
if(sLogFile != "")
{
// open log file
OpenLog(sLogFile, sDescription + " " + m_sFileName);
}
IXMLDOMNode * pElemNode = NULL;
IXMLDOMNode * pAttrNode = NULL;
_bstr_t bElementPattern(sElementPattern.c_str());
try
{
// get element node
hRes = m_pXMLKad->selectSingleNode(bElementPattern, &pElemNode);
if(hRes == S_FALSE)
{
hRes = S_FALSE;
throw string("node access error");
}
if(sAttributePattern.length())
{
// get attribute node by pattern string
_bstr_t bAttributePattern(sAttributePattern.c_str());
hRes = pElemNode->selectSingleNode(bAttributePattern, &pAttrNode);
if(hRes == S_FALSE)
{
throw string("node access error");
}
// set attribute value
_bstr_t bAttlanguage(sValue.c_str());
VARIANT vAttlanguage;
vAttlanguage.vt = VT_BSTR;
V_BSTR(&vAttlanguage) = bAttlanguage.copy();
hRes = pAttrNode->put_nodeValue(vAttlanguage);
VariantClear(&vAttlanguage);
}
else
{
// set element value
hRes = SetValue(pElemNode, sValue);
}
if(hRes == S_OK)
{
SaveXMLFile(m_sFileName, m_pXMLKad);
// log changes
Log("SetValueByPattern - Set value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue);
}
//delete pwAttlanguage;
if(FAILED(hRes))
{
hRes = S_FALSE;
throw string("value error");
}
}
catch(string str)
{
hRes = S_FALSE;
// log changes
Log("SetValueByPattern - Set value failed: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue);
Log("ERROR: " + str);
}
if(pElemNode != NULL)
pElemNode->Release();
if(pAttrNode != NULL)
pAttrNode->Release();
// close log file
CloseLog();
return hRes;
}
示例5: GetValueByPattern
HRESULT CKADmerge::GetValueByPattern(string sElementPattern,
string sAttributePattern,
string & sValue,
string sLogFile)
{
HRESULT hRes = 0;
if(sLogFile != "")
{
// open log file
OpenLog(sLogFile, sDescription + " " + m_sFileName);
}
IXMLDOMNode * pElemNode = NULL;
IXMLDOMNode * pAttrNode = NULL;
_bstr_t bElementPattern(sElementPattern.c_str());
try
{
// get element node by pattern string
hRes = m_pXMLKad->selectSingleNode(bElementPattern, &pElemNode);
if(hRes == S_FALSE)
{
throw string("node access error");
}
if(sAttributePattern.length())
{
// get attribute node by pattern string
_bstr_t bAttributePattern(sAttributePattern.c_str());
hRes = pElemNode->selectSingleNode(bAttributePattern, &pAttrNode);
if(hRes == S_FALSE)
{
throw string("node access error");
}
// get attribute value
sValue = GetValue(pAttrNode);
}
else
{
// get element value
sValue = GetValue(pElemNode);
}
hRes = S_OK;
// log changes
Log("GetValueByPattern - Get value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' is: " + sValue);
}
catch(string str)
{
sValue = "";
hRes = S_FALSE;
// log changes
Log("GetValueByPattern - Get value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern);
Log("ERROR: " + str);
}
if(pElemNode != NULL)
pElemNode->Release();
if(pAttrNode != NULL)
pAttrNode->Release();
// close log file
CloseLog();
return hRes;
}