xml

using System.Xml.Linq;

protected static string file = System.Web.HttpContext.Current.Server.MapPath("~/test/ruonanxiao.xml");
        public static string GetName()
        {
            string name = string.Empty;
            XElement doc = XElement.Load(file);
            var names = from p in doc.Descendants("name")
                        select p.Value;
            foreach (var n in names)
            {
                name = n;
            }
            return name;
        }

        public static string GetSex()
        {
            string name = string.Empty;
            XElement doc = XElement.Load(file);
            var names = from p in doc.Descendants("sex")
                        select p.Value;
            foreach (var n in names)
            {
                name = n;
            }
            return name;
        }

        public static string GetAge()
        {
            string name = string.Empty;
            XElement doc = XElement.Load(file);
            var names = from p in doc.Descendants("age")
                        select p.Value;
            foreach (var n in names)
            {
                name = n;
            }
            return name;
        }

原文地址:https://www.cnblogs.com/ruonanxiao/p/2439789.html