C#项目5.4

xiaoxiao2021-02-27  233

先列计划 列出每一步的大概内容 交互思路 人机交互和业务逻辑分离 数据存放 从各种数据源读取信息,抽象到数据结构,储存到容器

读取xml 声明命名空间:using System.Xml.Linq;

//打开XML文档 XDocument document = XDocument.Load(fileName); //获取根元素 XElement rootElement = document.Root; //在元素按索引读取值 foreach (var attribute in rootElement.Attributes("SrotType")) { SortType = ToSortType(attribute.Value.ToString()); } //获取根元素下的子元素 foreach (XElement element in rootElement.Elements()) { LimitBase limit = new LimitBase(); //获取元素内的变量 foreach (var attribute in element.Attributes()) { if (attribute.Name == "Id") { limit.Id = Convert.ToInt32(attribute.Value);//获取变量的值 } }

Foreach 通过中间节点读取容器节点的数据 for 通过i选取容器节点,直接读写容器节点

转载请注明原文地址: https://www.6miu.com/read-8563.html

最新回复(0)