tags:

views:

69

answers:

2

Here is my parsing code:

MSXML2::IXMLDOMNodePtr pNode = m_pXmlDoc->selectSingleNode(kNameOfChild.c_str());

MSXML2::IXMLDOMNodeListPtr pIDOMNodeList = NULL;
MSXML2::IXMLDOMNodePtr pIDOMNode = NULL;
long numOfChildNodes= 0;
BSTR bstrItemText;
HRESULT hr;

MSXML2::IXMLDOMElementPtr pChildNode = m_pXmlDoc->getElementsByTagName(kNameOfChild.c_str());


hr  = m_pXmlDoc->get_childNodes(&pIDOMNodeList);

hr = pIDOMNodeList->get_length(&numOfChildNodes);

And my xml file:

<?xml version="1.0"?>
<GovTalkMessage>
<EnvelopeVersion>1.0</EnvelopeVersion>
<Header>
  <MessageDetails>
     <Class>MOSWTSC2</Class>
     <Qualifier>acknowledgement</Qualifier>
     <Function>submit</Function>
     <TransactionID>20021202ABC</TransactionID>
     <CorrelationID>B07B9ED3176193DDC4EC39063848A927</CorrelationID>
     <ResponseEndPoint PollInterval="10">
      https://secure.gateway.gov.uk/poll
     </ResponseEndPoint>
     <GatewayTimestamp>2001-01-31T10:20:18.345</GatewayTimestamp>
  </MessageDetails>
  <SenderDetails/>
 </Header>
<GovTalkDetails>
   <Keys/>
</GovTalkDetails>
<Body/>
</GovTalkMessage>
  • kNameOfchild is "Qualifier"
  • pNode is always NULL
  • pChildNode is always NULL
  • hr returns S_OK
  • numOfChildNodes is always 0

So, what am I doing wrong? Thanks

A: 

You need to provide the xpath for the selectSingleNode call. There may be multiple "Qualifier" present in XML file, so in case you just pass "Qualifier" parser doesn't know which one to return. I haven't used XPath too many times, but I think this string should work for querying: "Header/MessageDetails[0]/Qualifier"

Naveen
nope. I will update you if i find something.
cbrulak
+1  A: 

Try /GovTalkMessage/Header/MessageDetails/Qualifier for the XPath query.

Luke