Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys in my below code it checks for only 1 node whether that node is present or not. similarly i want to check the same for multiple specific node in same xml. so how do i do it.

reboot.xml
XML
<rebootexclusiondata>
<memid>123</memid>
<siteid>123</siteid>
<regid>12345</regid>
<createdby>tanvi</createdby>
<updatedby>null</updatedby>
<exclusion>true</exclusion>
<dcdtime>2015-08-25 10:12:13</dcdtime>
<updcdtime>2015-08-25 10:12:13</updcdtime>
</rebootexclusiondata>

xmlparse.cpp:
void queryNodes()
{
	HRESULT hr = S_OK;
	IXMLDOMDocument *pXMLDom = NULL;
	IXMLDOMNodeList *pNodes = NULL;
	IXMLDOMNode *pNode = NULL;
	IXMLDOMNode *pNode1 = NULL;
	BSTR bstrQuery1 = NULL;
	BSTR bstrQuery2 = NULL;
	BSTR bstrNodeName = NULL;
	BSTR bstrNodeValue = NULL;
	VARIANT_BOOL varStatus;
	VARIANT varFileName;
	VariantInit(&varFileName);
	//<siteid>123</siteid>
	CHK_HR(CreateAndInitDOM(&pXMLDom));
	CHK_HR(VariantFromString(L"stocks.xml", varFileName));
	CHK_HR(pXMLDom->load(varFileName, &varStatus));
	if (varStatus != VARIANT_TRUE)
	{
		CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
	}
	// Query a single node.
	//bstrQuery1 = SysAllocString(L"//rebootexclusiondata[2]/*");
	bstrQuery1 = SysAllocString(L"//rebootexclusiondata//exclusion//");
	
	CHK_ALLOC(bstrQuery1);
	CHK_HR(pXMLDom->selectSingleNode(bstrQuery1, &pNode));
	if (pNode)
	{
		printf("Result from selectSingleNode:\n");
		CHK_HR(pNode->get_nodeName(&bstrNodeName));
		CHK_HR(pNode->get_xml(&bstrNodeValue));
		SysFreeString(bstrNodeName);
		printf("Node, <%S>:\n", bstrNodeName);
		printf("\t%S\n%S\n", bstrNodeValue);
		if (0 == wcscmp(bstrNodeValue, L"<exclusion>true</exclusion>"))
		{
			printf("\n exe exit \n\n");
		}
		else
		{
			printf("\n go further! lets reboot the system\n\n");
		}
		SysFreeString(bstrNodeValue);
		SAFE_RELEASE(pNode);
	}


now in this code it checks whether

<siteid>123</siteid>
is present along with
XML
<exclusion>true</exclusion>

or not
Posted
Updated 26-Aug-15 1:13am
v4

1 solution

If you had better read the documentation you would had found the function IXMLDOMNode::get_nextSibling.

It's all there. Normally interfaces and classes provide an API in which all standard tasks are included. It is a quality feature. ;-)
 
Share this answer
 
Comments
Member 11460314 26-Aug-15 7:18am    
its not i want next sibling. is there any alternate to it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900