Accessing the child node in DOM XML??
-
Hi, I want to access the data of node "sequence" and "prompt" in following DOM XML.
BSTR bstrResponse = SysAllocString( L"<Item>" L"<serviceProvider>Test</serviceProvider>" L"<scanSerialNumberPrompt>" L"<sequence>1</sequence>" L"<prompt>Serial Number</prompt>" L"</scanSerialNumberPrompt>" L"</Item>");
I am using the following codeMSXML2::IXMLDOMNodePtr pNodeItem = NULL; MSXML2::IXMLDOMNodePtr pNode = NULL; MSXML2::IXMLDOMNodePtr CurrentChildNode = NULL; MSXML2::IXMLDOMNodePtr CurrentNode = NULL; pNodeItem = CurrentNode->selectSingleNode("serviceProvider"); pNodeItem =CurrentNode->selectSingleNode("scanSerialNumberPrompt"); for (CurrentChildNode=pNodeItem->firstChild; CurrentChildNode!=NULL; CurrentChildNode = CurrentChildNode->nextSibling) { pNode = CurrentChildNode->selectSingleNode("sequence"); pNode = CurrentChildNode->selectSingleNode("prompt"); }
I am getting the null value in "pNode". Can you please let me know what is the error in accessing the child node in DOM XML. Thanks :) -- modified at 8:33 Monday 24th April, 2006 -
Hi, I want to access the data of node "sequence" and "prompt" in following DOM XML.
BSTR bstrResponse = SysAllocString( L"<Item>" L"<serviceProvider>Test</serviceProvider>" L"<scanSerialNumberPrompt>" L"<sequence>1</sequence>" L"<prompt>Serial Number</prompt>" L"</scanSerialNumberPrompt>" L"</Item>");
I am using the following codeMSXML2::IXMLDOMNodePtr pNodeItem = NULL; MSXML2::IXMLDOMNodePtr pNode = NULL; MSXML2::IXMLDOMNodePtr CurrentChildNode = NULL; MSXML2::IXMLDOMNodePtr CurrentNode = NULL; pNodeItem = CurrentNode->selectSingleNode("serviceProvider"); pNodeItem =CurrentNode->selectSingleNode("scanSerialNumberPrompt"); for (CurrentChildNode=pNodeItem->firstChild; CurrentChildNode!=NULL; CurrentChildNode = CurrentChildNode->nextSibling) { pNode = CurrentChildNode->selectSingleNode("sequence"); pNode = CurrentChildNode->selectSingleNode("prompt"); }
I am getting the null value in "pNode". Can you please let me know what is the error in accessing the child node in DOM XML. Thanks :) -- modified at 8:33 Monday 24th April, 2006I would do it a bit differently:
....
....
pNodeItem =CurrentNode->selectSingleNode("scanSerialNumberPrompt");
if (NULL != pNodeItem)
{
MSXML::IXMLDOMNodeListPtr pXMLNodeList = pNodeItem->selectNodes(_T("sequence"));
if (NULL != pXMLNodeList)
{
MSXML::IXMLDOMNodePtr pXmlNode = NULL;
for(int i = 0; i < pXMLNodeList->length; i++)
{
pXMLNode = pXMLNodeList->nextNode();
if(pXMLNode)
{
_bstr_t bsTxt = pXMLNode->getText();
........
Do what ever you want with the text here
........
}
}
}
}same thing for "prompt" Hope this helps you Yaron Ask not what your application can do for you, Ask what you can do for your application
-
I would do it a bit differently:
....
....
pNodeItem =CurrentNode->selectSingleNode("scanSerialNumberPrompt");
if (NULL != pNodeItem)
{
MSXML::IXMLDOMNodeListPtr pXMLNodeList = pNodeItem->selectNodes(_T("sequence"));
if (NULL != pXMLNodeList)
{
MSXML::IXMLDOMNodePtr pXmlNode = NULL;
for(int i = 0; i < pXMLNodeList->length; i++)
{
pXMLNode = pXMLNodeList->nextNode();
if(pXMLNode)
{
_bstr_t bsTxt = pXMLNode->getText();
........
Do what ever you want with the text here
........
}
}
}
}same thing for "prompt" Hope this helps you Yaron Ask not what your application can do for you, Ask what you can do for your application