gpt4 book ai didi

c# - 如何获取root的xml属性值?

转载 作者:数据小太阳 更新时间:2023-10-29 01:55:37 24 4
gpt4 key购买 nike

问:

如何通过 LINQ 获取根元素(我的 xml 文件中的第一个元素)的属性值。

.cs :

 XDocument xmlDoc = XDocument.Load(targetFileName);

.xml :

<timetable ascttversion="2010"  options="idprefix:realID">

我想读取 options 值。

最佳答案

像这样:

XDocument xdoc = XDocument.Load(targetFileName);
var attrib = xdoc.Root.Attribute("options").Value;

// attrib = "idprefix:realID"

关于c# - 如何获取root的xml属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8384797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com