C#读取XML属性解决方法

C#读取XML属性解决方法

Xml示例<ESBReturn xmlns='http://123'> <ESBHeader Status='1' Remarks='1' ReturnTime='2018/11/14 14:42:54' /> <ESBBody> <BusinessResponse> <![CDATA[<rows><row PatientCode='ABC323' PatientName='宝之' ScreeningScore='4' ScreeningApprise='NRS2002评分结果:4分,患者具有营养风险,应开始制定营养治疗计划(包括治疗膳食,经口营养补充,肠内营养及肠外营养)。' IsRisk='True' ScreenDate='2018/7/27 23:05:38'></row></rows>]]> </BusinessResponse> </ESBBody> </ESBReturn>

读取节点row当中的 PatientCode、PatientName。。。中的值

var xml = new XmlDocument();
xml.LoadXml(@"xml")
var xmlrow = new XmlDocument();
 xmlrow.LoadXml(xml.InnerText);
 //读取此节点上的属性,返回一个List
XmlNodeList elemlist = xmlrow.GetElementsByTagName("row");
 for (int i = 0; i < elemlist.Count; i++)
                {
                    string PatientCode = elemlist[i].Attributes["PatientCode"].Value;
                    string PatientName = elemlist[i].Attributes["PatientName"].Value;
                    string Score = elemlist[i].Attributes["ScreeningScore"].Value;
                    string Apprise = elemlist[i].Attributes["ScreeningApprise"].Value;
                }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值