返回首页
当前位置: 主页 > 编程语言 > XML教程 >

如何遍历获取Xml子节点值

时间:2015-08-28 00:09来源:电脑教程学习网 www.etwiki.cn 编辑:admin

待处理的Xml文件:

<?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>

只获取<sendresult>节点下的信息

XmlDocument Xd = new XmlDocument();
Xd.Load("E:\\Books.xml");
XmlNode root = Xd.DocumentElement;

foreach (XmlNode xmlNode in root.ChildNodes)
{
foreach (XmlNode xmlElement in xmlNode.ChildNodes)
{
MessageBox.Show(xmlElement.InnerText);
}
}

MessageBox.Show会弹出billpk、bdocid、filename、resultcode、resultdescription、content等节点的信息
------分隔线----------------------------
标签(Tag):xml
------分隔线----------------------------
推荐内容
猜你感兴趣