strxml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<ResultList>
<Result>
<ErrorID>-1</ErrorID>
<Description>系统处理单据出错</Description>
<PosCount>1</PosCount>
</Result>
<Result>
<ErrorID>10302</ErrorID>
<Description>访问数据库错误!</Description>
<PosCount></PosCount>
</Result>
<Result>
<ErrorID>10302</ErrorID>
<Description>访问数据库错误!</Description>
<PosCount></PosCount>
</Result>
<Result>
<ErrorID>0</ErrorID>
<Description>发送成功</Description>
<Count>2</Count>
<ErrorCount>0</ErrorCount>
</Result>
</ResultList>"这是一格xml 的字符串,
我想写个读取的方法:
private void ParseXml(string strXml)
{
string errorID="";
string strErrorDetail="";
string strPosCount="";
string strErrorCount="";
string strCount = "";
XmlDocument xd = new XmlDocument();
xd.LoadXml( strXml);
XmlNodeList xnRoot= xd.DocumentElement.SelectNodes ("//Result");
foreach(XmlNode node in xnRoot)
{ XmlNode errorIDNode = node.SelectSingleNode("//ErrorID");
XmlNode ErrorDetailNode = node.SelectSingleNode("//Description"); XmlNode CountNode = node.SelectSingleNode("//Count");
XmlNode ErrorCountNode = node.SelectSingleNode("//errorCount");
XmlNode PosCountNode = node.SelectSingleNode("//PosCount");
if (errorIDNode!=null)
{
errorID =errorIDNode.InnerText;
}
if(ErrorDetailNode!=null)
{
strErrorDetail = ErrorDetailNode.InnerText;
}
if(CountNode!=null)
{
strCount = CountNode.InnerText;
}
if(ErrorCountNode!=null)
{
strErrorCount = ErrorCountNode.InnerText;
}
if(PosCountNode!=null)
{
strPosCount = PosCountNode.InnerText;
}
// private string strError ="";在上面定义的
this.strError += showError( PosCount,errorID,strErrorDetail);
}
}//showError( PosCount,errorID,strErrorDetail) 这个方法是 显示信息的
public string showError(int poscount, string errorCode , string errorDetail)
{
string displayMessage="";
if(poscount>0)
{
displayMessage = "\r\n"
+ " >> 错误为第:" + poscount + "条\r\n"
+ " >> 错误代码:" + errorCode + "\r\n"
+ " >> 错误信息:" + errorDetail + "\r\n"; return displayMessage;
}
else
{
displayMessage = "\r\n"
+ " >> 错误代码:" + errorCode + "\r\n"
+ " >> 错误信息:" + errorDetail + "\r\n";
}
}
为什么 我显示的4 条 记录, 都是 第一条 记录 ,其他的不显示
<ResultList>
<Result>
<ErrorID>-1</ErrorID>
<Description>系统处理单据出错</Description>
<PosCount>1</PosCount>
</Result>
<Result>
<ErrorID>10302</ErrorID>
<Description>访问数据库错误!</Description>
<PosCount></PosCount>
</Result>
<Result>
<ErrorID>10302</ErrorID>
<Description>访问数据库错误!</Description>
<PosCount></PosCount>
</Result>
<Result>
<ErrorID>0</ErrorID>
<Description>发送成功</Description>
<Count>2</Count>
<ErrorCount>0</ErrorCount>
</Result>
</ResultList>"这是一格xml 的字符串,
我想写个读取的方法:
private void ParseXml(string strXml)
{
string errorID="";
string strErrorDetail="";
string strPosCount="";
string strErrorCount="";
string strCount = "";
XmlDocument xd = new XmlDocument();
xd.LoadXml( strXml);
XmlNodeList xnRoot= xd.DocumentElement.SelectNodes ("//Result");
foreach(XmlNode node in xnRoot)
{ XmlNode errorIDNode = node.SelectSingleNode("//ErrorID");
XmlNode ErrorDetailNode = node.SelectSingleNode("//Description"); XmlNode CountNode = node.SelectSingleNode("//Count");
XmlNode ErrorCountNode = node.SelectSingleNode("//errorCount");
XmlNode PosCountNode = node.SelectSingleNode("//PosCount");
if (errorIDNode!=null)
{
errorID =errorIDNode.InnerText;
}
if(ErrorDetailNode!=null)
{
strErrorDetail = ErrorDetailNode.InnerText;
}
if(CountNode!=null)
{
strCount = CountNode.InnerText;
}
if(ErrorCountNode!=null)
{
strErrorCount = ErrorCountNode.InnerText;
}
if(PosCountNode!=null)
{
strPosCount = PosCountNode.InnerText;
}
// private string strError ="";在上面定义的
this.strError += showError( PosCount,errorID,strErrorDetail);
}
}//showError( PosCount,errorID,strErrorDetail) 这个方法是 显示信息的
public string showError(int poscount, string errorCode , string errorDetail)
{
string displayMessage="";
if(poscount>0)
{
displayMessage = "\r\n"
+ " >> 错误为第:" + poscount + "条\r\n"
+ " >> 错误代码:" + errorCode + "\r\n"
+ " >> 错误信息:" + errorDetail + "\r\n"; return displayMessage;
}
else
{
displayMessage = "\r\n"
+ " >> 错误代码:" + errorCode + "\r\n"
+ " >> 错误信息:" + errorDetail + "\r\n";
}
}
为什么 我显示的4 条 记录, 都是 第一条 记录 ,其他的不显示
解决方案 »
- 向高手求一个算法
- 谁有C#简单的RPG游戏源码,或是一个人物走动的代码
- 急求对repeater的好的分页技术,那位大大能提供一个啊
- 高分讨论关于中间层WebService的安全访问问题
- 一个FORM分两个区域,左边一个是一个Tree,如何在选中某一个节点后,让右边区域全部改掉,也就是换成另外一个控件.
- C#编程要怎么学习才能入门快点
- 关于 yield语句和内存加载.
- 请问在winform中,在父窗口中打开一个子窗口,在子窗口中输入数据保存之后,如何更新父窗口的datagrid?在线等,急呀!
- 求visual studio .net 2003 英文企业架构版高速下载地址。中文版勿扰。
- 用了Gautil安装了一些dll后,在哪里看安装了哪些DLL,如何反安装
- SelectSingleNode的问题
- 我该不该发布辛苦开发的。net控件?
>> 错误为第:1条
>> 错误代码:-1
>> 错误信息:系统处理单据出错 >> 错误为第:1条
>> 错误代码:-1
>> 错误信息:系统处理单据出错 >> 错误为第:1条
>> 错误代码:-1
>> 错误信息:系统处理单据出错 >> 错误为第:1条
>> 错误代码:-1
>> 错误信息:系统处理单据出错
结果确实这样 的
{
PosCount = Convert.ToInt32(strPosCount);
}
解析的时候 还有这个 ,忘记贴上了,怕太长了,
放在 if(PosCountNode!=null)
{
strPosCount = PosCountNode.InnerText;
}的下面了一行
每个节点依次的读取。
node已经是在遍历了.