Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accessing the child node in DOM XML??

Accessing the child node in DOM XML??

Scheduled Pinned Locked Moved C / C++ / MFC
questionhtmlxmlhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    itkid
    wrote on last edited by
    #1

    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 code MSXML2::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

    Y 1 Reply Last reply
    0
    • I itkid

      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 code MSXML2::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

      Y Offline
      Y Offline
      YaronNir
      wrote on last edited by
      #2

      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

      I 1 Reply Last reply
      0
      • Y YaronNir

        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

        I Offline
        I Offline
        itkid
        wrote on last edited by
        #3

        Thank you very much Yaron!! your solution is working fine. I wish, I could got the exact problem of my code too. Regards ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups