MSXML: Unable to get node value

I am writing an application to load xml file and retriev a node value (refer to the xml sample, I am trying to get "memberNumber"), but always get null value.
anyone can hlpe look into the problem ? thanks guys.
Below is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[small]void ProcessMessage(char* strippedMessageData, int messageDataLength)
{
   std::cout << "porcess message length="<<messageDataLength<<"\n";
   std::cout<< "Received the following message :\n";
   std::cout<< &strippedMessageData << "\n";

   //load XML message into a Document Object Model
   HRESULT result;

   // Create the Document Object Model to store the message's XML in
   MSXML2::IXMLDOMDocument2Ptr messageDOM;
   result = messageDOM.CreateInstance(__uuidof(MSXML2::DOMDocument60));
   if (FAILED(result)) 
   {
     return;
   }

   try
   {
	// Load the message's XML text into the Document Object Model so we can parse it
	if(messageDOM->loadXML(strippedMessageData)!= VARIANT_TRUE)
	{
          return;
	} 
	MSXML2::IXMLDOMElementPtr element = messageDOM->GetdocumentElement();
	MSXML2::IXMLDOMNodePtr pParentNode =   element->selectSingleNode("ERAContract"); 
	if(pParentNode !=NULL  && pParentNode->hasChildNodes() ) 
	{
	 MSXML2::IXMLDOMNodePtr pChildNode =   pParentNode->selectSingleNode("ERAVehicleDetails"); 
	if(pChildNode !=NULL  && pParentNode->hasChildNodes() ) 
	{
	  MSXML2::IXMLDOMNodePtr pChildNode2 =   pChildNode->selectSingleNode("memberNumber"); 
	 if(pChildNode2 !=NULL  )
	{
	   VARIANT varValue;// =	pChildNode2->nodeValue;
	   HRESULT hr1 = pChildNode2->get_nodeValue(&varValue);
	 //The app always comes here and get S_FALSE result..!!
    	  if(hr1==S_OK)
	  {
		string  memberNumber =_bstr_t(varValue);
		std::cout<<"--- memberNumber="<<memberNumber<<"\n";
   	}
    }
 }
}
}
  catch(std::exception e)
{
	std::cout <<" exception:" <<e.what()<<"\n";
}
catch(...)
{
}
 }[/small]


an xml sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0"?>
<NS1:modifyERAContractRequest xmlns:NS1="http://www.xxx.com/ModifyERAContract" xmlns:CSModifyERAContractRequest="ModifyERAContractRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<serviceHeader>
  <version>1.0</version>
  <requestID>3321692771592536</requestID>
  <languageCode>100</languageCode>
</serviceHeader>
<modifyAction>0</modifyAction>
<ERAContract>
  <ERAVehicleDetails>
	<memberNumber>6052022</memberNumber>
	<policyNumber>0030001610001000</policyNumber>
	<memberDebt/>
	<joinedDate>2010-06-07</joinedDate>
	<renewalDate>2011-06-06</renewalDate>
	<vehicleWeight>    0</vehicleWeight>
 </ERAVehicleDetails>
See http://msdn.microsoft.com/en-us/library/windows/desktop/ms756022(v=vs.85).aspx for an explanation. What you need to do is get the first child of the memberNumber node, and then use get_nodeValue() on that node. Basically, to obtain the text inside the node you obtain the child of that node that is of type NODE_TEXT.
thanks webJose. it works now.
Topic archived. No new replies allowed.