循环读取重名节点的方法

王朝other·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

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

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航