C# 读取xml节点值 实例

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

 

posted @ 2015-04-07 16:34    阅读(349)  评论(0编辑  收藏  举报