zoukankan      html  css  js  c++  java
  • C#读取XML

            /// <summary>
            ///读取xml的方法
            /// </summary>
            /// <returns></returns>
            public List<People> GetXml()
            {
                List<People> list = new List<People>();
                XmlDocument xmldoc = new XmlDocument();
                //获取物理路径
                string path = Server.MapPath("/Content/user.xml");
                //加载xml文档
                xmldoc.Load(path);
                //第一个节点
                XmlNode xmlnode = xmldoc.SelectSingleNode("CATALOG");
                //遍历子节点
                foreach (XmlNode node in xmlnode)
                {
                    list.Add(new People() 
             { Name = node.ChildNodes[0].InnerText,
    Sex = node.ChildNodes[1].InnerText,
    Age = Convert.ToInt32(node.ChildNodes[2].InnerText),
    Description = node.ChildNodes[3].InnerText
    }); }
    return list; }
    <?xml version="1.0" encoding="utf-8"?>
    <CATALOG>
      <people>
        <name>wuboo</name>
        <sex>man</sex>
        <age>21</age>
        <description>You’re more than a shadow, I’ve just to believe.</description>
      </people>
      <people>
        <name>laqi</name>
        <sex>man</sex>
        <age>24</age>
        <description>Remember, always laugh when you can. It's cheaper than medicine. </description>
      </people>
      <people>
        <name>masa</name>
        <sex>woman</sex>
        <age>23</age>
        <description>From now on, I will expect nothing, and just take what I get.</description>
      </people>
    </CATALOG>
  • 相关阅读:
    基础总结篇之一:Activity生命周期
    putExtra方法
    fork函数
    linux中fork()函数详解(原创!!实例讲解) (转载)
    系统调用wait、waitpid和exec函数
    版本控制工具VSS使用介绍
    学习进度条六(第七周)
    阶段冲刺4
    阶段冲刺3
    阶段冲刺2
  • 原文地址:https://www.cnblogs.com/talentzemin/p/3998033.html
Copyright © 2011-2022 走看看