<?xml version="1.0" encoding="utf-8" ?>
<shenhe>
    <shenhes>
        <value>1</value>
    </shenhes>
</shenhe>
c# 读取xml中 单个的节点的值  如上面所示  如何读到那个1
请大大们 给我写详细点 什么引用啊 注释啊  我很笨  大家费心

解决方案 »

  1.   

    先引用using System.Xml;
    XmlDocument xml = new XmlDocument();
    xml.Load(@"d:\test.xml");
    XmlNode node = xml.SelectSingleNode("/shenhe/shenhes/value");
    Response.Write(node.InnerText);
      

  2.   

    xmldocument
     getelementBytag(“value”).innertext
      

  3.   

    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load(@"文件路径");
    Xmlnode node=xmlDoc.SelectSingleNode(@"/shenhe/shenhes/value");
    输出:node.InnerXml;开头using System.Xml;
      

  4.   

    将节点字段写成实体类。public void BindXml()
            {
                List<MarketProject.platform.modules.Information> list = new List<MarketProject.platform.modules.Information>();
                //实例化xml
                XmlDocument xml = new XmlDocument();
                //读取xml文件
                xml.Load(@"F:\\360data\\重要数据\\桌面\\Update_umis\\01.WebProject\\MarketProject\\et\\Test.xml");  //你的xml地址
                string id = "";
                string name = "";
                string sex = "";
                MarketProject.platform.modules.Information info = null;
                //////////*******下面开始循环读取xml文件信息********/
                ///////////////
                foreach (XmlNode node in xml.ChildNodes)
                {
                    if (node.Name == "abc")
                    {
                        foreach (XmlNode node1 in node.ChildNodes)
                        {
                            if (node1.Name == "item")
                            {
                                foreach (XmlNode node2 in node1.ChildNodes)
                                {
                                    switch (node2.Name)
                                    {
                                        case "id":
                                            id = node2.InnerText;
                                            break;
                                        case "name":
                                            name = node2.InnerText;
                                            break;
                                        default:
                                            sex = node2.InnerText;
                                            break;
                                    }
                                }
                                info = new MarketProject.platform.modules.Information(id, name, sex);
                                //将信息保存至集合
                                list.Add(info);
                            }
                        }
                    }
                }
                GridView1.DataSource = list;
                GridView1.DataBind();
            }
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;namespace MarketProject.platform.modules
    {
        public class Information
        {
            private string id;
            public string Id
            {
                get { return id; }
                set { id = value; }
            }
            private string name;
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            private string sex;
            public string Sex
            {
                get { return sex; }
                set { sex = value; }
            }
            public Information()
            {        }
            public Information(string id, string name, string sex)
            {
                this.Id = id;
                this.Name = name;
                this.Sex = sex;
            }    }
    }