![](/img/trans.png)
[英]How to set a default value for attribute if it doesn't exist in the XDocument object
[英]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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.