zoukankan      html  css  js  c++  java
  • XML Linq 学习笔记

    XML如下:

    <?xml version="1.0" encoding="utf-8"?>
    <Dishes>
        <Dish>
            <Name>清新芦荟</Name>
            <Category>饮料</Category>
            <Comment></Comment>
            <Score>5</Score>
        </Dish>
        <Dish>
            <Name>薄荷汽水</Name>
            <Category>饮料</Category>
            <Comment>本店特色</Comment>
            <Score>5</Score>
        </Dish>
    </Dishes>

    读取方法:

            public List<Dish> GetAllDishes()
            {
                List<Dish> dishList = new List<Dish>();
                string xmlFileName = System.IO.Path.Combine(Environment.CurrentDirectory, @"DataData.xml");
                //读取XML
                XDocument xDoc = XDocument.Load("xmlFileName");
                //返回Dishes集合
                var dishes = xDoc.Descendants("Dish");
                //循环集合 ,把数据添加到List中
                foreach(var d in dishes)
                {
                    Dish dish = new Dish();
                    dish.Name = d.Element("Name").Value;
                    dish.Category = d.Element("Category").Value;
                    dish.Comment = d.Element("Comment").Value;
                    dish.Score = double.Parse(d.Element("Score").Value);
                    dishList.Add(dish);
                }
                return dishList;
            }
  • 相关阅读:
    资源列表
    资源列表
    编程语言资源列表
    PyTorch简介
    Keras构建回归神经网络
    Keras简介
    Tensorflow之RNN,LSTM
    Tensorflow之CNN
    Tensorflow之dropout
    Tensorflow做分类
  • 原文地址:https://www.cnblogs.com/yuejian/p/10696384.html
Copyright © 2011-2022 走看看