繁体   English   中英

如何获取XDocument对象中的属性

[英]How to get attribute in the XDocument object

我有这个xml

<config>
    <audio first="true" second="false" third="true" />
</config>

我希望我的代码能够做到这样的事情

if (xdoc.getAttr("first")=="true")
    Console.Write("first is true");

如何使用LINQ XDocument执行此操作? 到目前为止我所拥有的是用该xml字符串加载的XDocument对象。

您需要获取<audio>元素的属性:

string value = xdoc.Root.Element("audio").Attribute("first").Value;

你应该看看XElement

文章在c-sharpcorner.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM