0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.