我有这个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;

关于c# - 如何在XDocument对象中获取属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4429903/

10-13 06:20