欢迎访问 水平网, 今天是:2010年09月09日 [订阅本站] [用户注册/登录] [收藏本站]
首     页 技术文章 注 册 码 代码仓库 资源下载 技术讨论 实用工具 站内搜索 联系我们
■ 当前位置:首页 >> 技术文章 >> 网页编程 >> 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;
}
■ 发表评论
您的称呼:
联系方式:
验 证 码 : 看不清楚?点击刷新验证码 看不清楚?点击图片刷新验证码
■ 最新评论显示所有评论