C# 读取xml文件内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace 读取xml内容
{
class Program
{
static void Main(string[] args)
{
Dictionary<long, string> dic = new Dictionary<long, string>();
string str = "C:\\Users\\CMS01\\Desktop\\cmsc2\\cmsc2\\cmsc2.cmwproj.user";//xml文件
XElement rootNode = XElement.Load(str);
var itemNode = rootNode.Elements("CompiledFiles");//xml文件中某一个节点
foreach(var element in itemNode.Elements())
{
if(element.Name.LocalName == "File")//筛选节点中内容
{
dic.Add(Convert.ToInt64(element.Value), element.FirstAttribute.Value);
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ProjectName="cmsc2" RecentCompiledTime="2022/7/11 9:03:12">
<CompiledFiles>
<File name="cs.c">1657247607</File>
<File name="11.h">1657247612</File>
<File name="24.h">1657011124</File>
<File name="3.h">1657077746</File>
<File name="4.h">1657258077</File>
</CompiledFiles>
</Project>
本文作者:cloud-sword
本文链接:https://www.cnblogs.com/cloud-sword/p/16469463.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步