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;
}