[此文来源于互联网,牛C网只负责收集整理]
怎麼樣把我下面的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;
}
怎麼樣把我下面的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;
}
作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/3388/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
牛C网推荐您再看看以下日志:
亲密接触xml(10)-其它例子
网络编程-如何生成XML数据
XSL的模板规则
利用XMLHTTP 从其他页面获取数据
WML学习(七)-CGI编程
XML入门教程-使用XSL显示XML
XML技术上传文件
读写一般格式的XML文件
教你学会XML Web Service 的基础
利用XMLHTTP无刷新添加数据之Post篇
亲密接触xml(10)-其它例子
网络编程-如何生成XML数据
XSL的模板规则
利用XMLHTTP 从其他页面获取数据
WML学习(七)-CGI编程
XML入门教程-使用XSL显示XML
XML技术上传文件
读写一般格式的XML文件
教你学会XML Web Service 的基础
利用XMLHTTP无刷新添加数据之Post篇
css式样重用、子选择器和组选择器
WML初级教程之关于WML文件的概念





