先上自己的代码笔记using System; using System.Collections.Generic; using System.IO; using System.Xml; namespace ConsoleApplication7 { class Program { static void Main(string[] args) { ////代码的路径 string xmlPath = @"D:\xmltests\test.xml"; if(File.Exists(xmlPath))//该xml文件是否存在 { Console.WriteLine(" The XML Exist!"); //读取 XmlDocument xmlDoc = new XmlDocument(); //加载路径里面的内容 xmlDoc.Load(xmlPath); //获取子节点 XmlNodeList list = xmlDoc.SelectSingleNode("Luna").ChildNodes; foreach(XmlElement xe in list) {//开始遍历 if(xe.Name=="days") { Console.WriteLine("The Element Exist!!!"); foreach(XmlElement day in xe) {//遍历子节点的子节点 if(day.Name=="day1") { Console.WriteLine(day.InnerText); } } } } } } } }
时间: 2024-10-11 15:29:48