What wrong with this clause??
-
Dear all, I try to select node from a XML file: but always failed: there are nodes in the file but the select result are no. What wrong with my code or the structure/name of my XML file? my code: -------------------------- MSXML::IXMLDOMDocumentPtr pDoc = NULL; MSXML::IXMLDOMElementPtr root; MSXML::IXMLDOMNodePtr userParent, userNode; MSXML::IXMLDOMNodeListPtr userList; root = pDoc->documentElement; userParent=root->selectSingleNode(_bstr_t("Users")); strServer="gmitc-data3"; strVolume="d:\Shared Volume"; temp=strServer+"\\"+strVolume; userList=userParent->selectNodes(_bstr_t\ ("User[@Class1Root='"+temp+"']")); for( int k=0; kGetlength(); k++) { m_nCount++; userNode=userList->Getitem(k); strUser=(LPCTSTR)_bstr_t(userNode->attributes\ ->getNamedItem(_bstr_t("Name"))->text); m_Grid.SetRows(m_nCount+1); m_Grid.SetTextArray(m_nCols*m_nCount+2,strUser); }// end for(userList) --------------------------- my xml file: --------------------------- " ---------------------------------
-
Dear all, I try to select node from a XML file: but always failed: there are nodes in the file but the select result are no. What wrong with my code or the structure/name of my XML file? my code: -------------------------- MSXML::IXMLDOMDocumentPtr pDoc = NULL; MSXML::IXMLDOMElementPtr root; MSXML::IXMLDOMNodePtr userParent, userNode; MSXML::IXMLDOMNodeListPtr userList; root = pDoc->documentElement; userParent=root->selectSingleNode(_bstr_t("Users")); strServer="gmitc-data3"; strVolume="d:\Shared Volume"; temp=strServer+"\\"+strVolume; userList=userParent->selectNodes(_bstr_t\ ("User[@Class1Root='"+temp+"']")); for( int k=0; kGetlength(); k++) { m_nCount++; userNode=userList->Getitem(k); strUser=(LPCTSTR)_bstr_t(userNode->attributes\ ->getNamedItem(_bstr_t("Name"))->text); m_Grid.SetRows(m_nCount+1); m_Grid.SetTextArray(m_nCols*m_nCount+2,strUser); }// end for(userList) --------------------------- my xml file: --------------------------- " ---------------------------------
"User[@Class1Root='"+temp+"']" appears wrong at first glance, since all User tags are contained within the Users tag. thus, that xpath should read "Users/User[@Class1Root='"+temp+"']" Also, you may want to develop on your local drive, and not over a network share. This eleminates a source of errors in your code, which may also be the reason. * Edit: looking at your code (imagine that :)), I see you retrieve the User tag at an earlier step, and then run the above xpath on that node. Perhaps ensure it works from a local file instead of a network share.
-
"User[@Class1Root='"+temp+"']" appears wrong at first glance, since all User tags are contained within the Users tag. thus, that xpath should read "Users/User[@Class1Root='"+temp+"']" Also, you may want to develop on your local drive, and not over a network share. This eleminates a source of errors in your code, which may also be the reason. * Edit: looking at your code (imagine that :)), I see you retrieve the User tag at an earlier step, and then run the above xpath on that node. Perhaps ensure it works from a local file instead of a network share.
-
Dear all, I try to select node from a XML file: but always failed: there are nodes in the file but the select result are no. What wrong with my code or the structure/name of my XML file? my code: -------------------------- MSXML::IXMLDOMDocumentPtr pDoc = NULL; MSXML::IXMLDOMElementPtr root; MSXML::IXMLDOMNodePtr userParent, userNode; MSXML::IXMLDOMNodeListPtr userList; root = pDoc->documentElement; userParent=root->selectSingleNode(_bstr_t("Users")); strServer="gmitc-data3"; strVolume="d:\Shared Volume"; temp=strServer+"\\"+strVolume; userList=userParent->selectNodes(_bstr_t\ ("User[@Class1Root='"+temp+"']")); for( int k=0; kGetlength(); k++) { m_nCount++; userNode=userList->Getitem(k); strUser=(LPCTSTR)_bstr_t(userNode->attributes\ ->getNamedItem(_bstr_t("Name"))->text); m_Grid.SetRows(m_nCount+1); m_Grid.SetTextArray(m_nCols*m_nCount+2,strUser); }// end for(userList) --------------------------- my xml file: --------------------------- " ---------------------------------
in line: strVolume="d:\Shared Volume"; you need to have strVolume="d:\\Shared Volume"; This will not show up as an error when u compile but as a warning about some escape characters. Always check warnings. Your code should not only be error free but also warning free. This could be another reason why your code did not work as your code will resolve to D:Share Volume while you are matching d:\shared......