1 xml文件
1 <?xml version="1.0" encoding="utf-8" ?> 2 <cultures> 3 <daojia> 4 <book> 5 <name> 道德经</name> 6 <author>老子</author> 7 </book> 8 <book> 9 <name> 文始真经</name> 10 <author>关尹子</author> 11 </book> 12 </daojia> 13 </cultures>
2 代码
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Xml.Linq; 7 8 namespace ConsoleApplication8 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 //1.xml文件的格式必须是正确的 15 XDocument file = XDocument.Load("1.xml"); 16 Console.WriteLine(file.Root.Name); 17 Console.ReadKey(); 18 } 19 } 20 }
3 效果
时间: 2024-11-05 06:27:32