zl程序教程

您现在的位置是:首页 >  其他

当前栏目

怎么读出Xml文件中某个节点、属性的信息

文件属性节点XML 怎么 信息 某个 读出
2023-09-14 09:02:14 时间
 ?xml version="1.0" encoding=UTF-8? 

 ufinterface billtype="gl" filename="gledi" isexchange="Y" proc="add" receiver="01" replace="Y" roottag="sendresult" sender="ceec" successful="Y" 

 sendresult 

 billpk 

 /billpk 

 bdocid AAAA /bdocid 

 filename BBBB /filename 

 resultcode CCCC /resultcode 

 resultdescription DDDD /resultdescription 

 content EEEE /content 

 /sendresult 

 sendresult 

 billpk 

 /billpk 

 bdocid aaaa /bdocid 

 filename bbbb /filename 

 resultcode cccc /resultcode 

 resultdescription dddd /resultdescription 

 content eeee /content 

 /sendresult 

 /ufinterface 

处理目标获取节点isexchange、billpk、resultcode、bdocid、resultdescription的节点信息,代码如下:
string Pzbh = string.Empty;// bdocid string Djxx = string.Empty;// resultdescription //遍历每个ufinterface节点 foreach (XmlNode node in Xd.SelectNodes("//ufinterface")) strID = node.Attributes["isexchange"].Value; //获取isexchange属性的值 XmlNode RootNode = Xd.SelectSingleNode("ufinterface");//得到根节点 //得到根节点下所有名为“sendresult”子节点,是一个list集合。 XmlNodeList ChildNodes = RootNode.SelectNodes("sendresult"); //遍历 sendresult 节点集合 foreach (XmlNode childnode in ChildNodes) //遍历每个 sendresult 节点中的子节点 foreach (XmlNode snode in childnode) if (snode.Name == "billpk") Xtfhz = snode.InnerText; MessageBox.Show("billpk=" + Xtfhz); if (snode.Name == "bdocid") Pzbh = snode.InnerText; MessageBox.Show("bdocid=" + Pzbh); if (snode.Name == "resultcode") Fhxxbh = snode.InnerText; MessageBox.Show("resultcode=" + Fhxxbh); if (snode.Name == "resultdescription") Djxx = snode.InnerText; MessageBox.Show("resultdescription=" + Djxx); catch (Exception ee) MessageBox.Show(ee.ToString()); } 在代码中的每个MessageBox.Show均可弹出,对应节点的信息。