本文介绍了如何获得在XDocument对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的XML

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



我想我的代码能够做这样的事。

I want my code to able to do something like this

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



我如何做到这一点的LINQ的XDocument?
我有什么到目前为止装入了XML字符串XDocument对象。

How do I do this with LINQ XDocument?What I have so far is the XDocument Object loaded with that xml string.

推荐答案

您需要获得的属性<音频> 元素:

You need to get the attribute of the <audio> element:

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

这篇关于如何获得在XDocument对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:30