码迷,mamicode.com
首页 > Windows程序 > 详细

C# 读取xml节点值 实例

时间:2015-04-07 17:31:52      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

xml文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<info>
  <error>
    <errorid errorNUM="E00001">
      <content>未登录,请登录</content>
    </errorid>
  </error>
  <error>
    <errorid errorNUM="S00001">
      <content>信息已提交,返回首页</content>
    </errorid>
  </error>
</info>

根据errorNum="S00001"读取content的值

        private void BindData()
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(AppDomain.CurrentDomain.BaseDirectory + "/H5page/xml/error.xml");

            foreach (XmlNode node in xml)
            {
                if (node.Name == "info")
                {
                    foreach (XmlNode node1 in node.ChildNodes)
                    {
                        if (node1.Name == "error")
                        {
                            foreach (XmlNode node2 in node1.ChildNodes)
                            {
                                if (node2.Attributes["errorNUM"].Value == errorNUM)
                                {
                                    errorcontent = node2.InnerText;
                                }
                            }
                        }
                    }
                }
            }
        }

 

C# 读取xml节点值 实例

标签:

原文地址:http://www.cnblogs.com/Wbely/p/4398666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!