慈心积善融学习,技术愿为有情学。善心速造多好事,前人栽树后乘凉。我今于此写经验,愿见文者得启发。
- .NET Framework : 4.6.1
- ide : visual studio 2017 community
- os : win7 x86_64
- type setting : markdown
- blog : https://blog.csdn.net/yushaopu
- github : https://github.com/GratefulHeartCoder
xml file
<?xml version="1.0" encoding="utf-8"?>
<cultures>
<taoists count="100" comment="good-t">
<book>
<name>道德经</name>
<author>老子</author>
</book>
<book>
<name>文始真经</name>
<author>关尹子</author>
</book>
</taoists>
<buddhism count="321" comment="good-d">
<book>
<name>金刚经</name>
<author>释迦牟尼</author>
</book>
<book>
<name>地藏菩萨本愿经</name>
<author>地藏</author>
</book>
</buddhism>
</cultures>
code
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// xml文件的格式必须是正确的
XDocument file = XDocument.Load("MyXMLFile.xml");
// 获取xml文件的根节点
XElement xmlRoot = file.Root;
// 获取根节点下的第一级子节点
IEnumerable<XElement> nodeFirst = xmlRoot.Elements();
foreach (var item in nodeFirst)
{
Console.WriteLine(item.Attribute("count").Name + " " + item.Attribute("count").Value);
}
Console.ReadKey();
}
}
}
result
count 100
count 321
resource
- [文档] https://docs.microsoft.com/zh-cn/dotnet/csharp/
- [平台] https://www.csdn.net/
- [ IDE ] https://visualstudio.microsoft.com/zh-hans/
感恩曾经帮助过 心少朴 的人。
C#优秀,值得学习。
Console,WinForm,WPF,ASP.NET,Azure WebJob,WCF,Unity3d可以适当地了解一下。
XML,DTD,XMLSchema,XSL,SVG可以适当地了解一下。
注:此文是自学笔记所生,质量中下等,故要三思而后行。新手到此,不可照搬,应先研究其理象数,待能变通之时,自然跳出深坑。