循环读取重名节点的方法

怎麼樣把我下面的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;  
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值