迴圈讀取重名節點的方法

來源:互聯網
上載者:User
迴圈 怎麼樣把我下面的xml格式的檔案裡面的結點中值迴圈讀出來  
<?xml  version="1.0"  standalone="yes"?>  
<InOutStore  xmlns="http://tempuri.org/InOutStore.xsd">  
   <OutStore>  
       <code>6900916200010</code>  
       <time>2005-7-11  20:47:54</time>  
   </OutStore>  
   <OutStore>  
       <code>1P25-68596-01</code>  
       <time>2005-7-11  20:48:10</time>  
   </OutStore>  
   <OutStore>  
       <code>6901028337168</code>  
       <time>2005-7-11  20:48:20</time>  
   </OutStore>  
   <OutStore>  
       <code>6901028337168</code>  
       <time>2005-7-11  20:48:32</time>  
   </OutStore>  
   <OutStore>  
       <code>6901028337168</code>  
       <time>2005-7-11  20:48:41</time>  
   </OutStore>  
   <PocketId>  
       <pid>001</pid>  
   </PocketId>  
</InOutStore>  
 
用 節點[索引]的模式可以讀取重名節點, 下面是代碼
#if  !defined(__MSXML3__)  
 
#define  __MSXML3__  
 
#import  "msxml3.dll"    
using  namespace  MSXML2;  
#endif  
 
           IXMLDOMDocument2Ptr  xml;  
xml.CreateInstance(__uuidof(MSXML2::DOMDocument));  
xml->load("xxxx.xml");  
 
CStringArray  timeA,  codeA;  
 
int  i=  1;  
BOOL  bNode  =  TRUE;  
while  (bNode)  
{  
 
IXMLDOMNodePtr  node;  
CString  strRoot;  
 
strRoot.Format("/InOutStore/OutStore[%d]",  i++);  
node=xml->selectSingleNode(_bstr_t(strRoot));  
if  (node)  
{  
     IXMLDOMNodePtr  nodeCode,  nodeTime;  
     VARIANT  value;  
     CString  strCode  =  strRoot  +  "/code";  
   nodeCode=xml->selectSingleNode(_bstr_t(strCode));  
     nodeCode->get_nodeTypedValue(&value);  
 
   CString  str1(value.bstrVal);  
   SysFreeString(value.bstrVal);  
   codeA.Add(str1);  
 CString  strTime  =  strRoot  +  "/time";  
   nodeTime=xml->selectSingleNode(_bstr_t(strTime  ));  
     nodeTime->get_nodeTypedValue(&value);  
 
   CString  str2(value.bstrVal);  
   SysFreeString(value.bstrVal);  
   timeA.Add(str2);  
}  
else  
       bNode  =  FALSE;  
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.