gpt4 book ai didi

linq - 使用 linq 在 xdocument 上搜索

转载 作者:行者123 更新时间:2023-12-01 09:36:37 25 4
gpt4 key购买 nike

我有一个字符串中的以下 xml:

<XMLClient>
<ClientData>
<Control type=1>BtnSave</control>
<Control type=2>Suppliers.aspx</control>
...
...
...
</clientData>
</XMLClient>

我想要做的是使用天气返回 true 或 false 记录/节点存在于控件的类型属性为 2 并且文本等于 Suppliers.aspx 的地方。

我想为此使用 linq,但我不知道我想我需要一些 linq 表达式,不太确定......

提前感谢您的任何建议!

最佳答案

这样的事情应该可以工作:

XDocument doc = XDocument.Load("test.xml");

bool nodeExists = doc.Descendants("Control")
.Where(x => x.Attribute("type") != null &&
x.Attribute("type").Value == "2" &&
x.Value == "Suppliers.aspx")
.Any();

关于linq - 使用 linq 在 xdocument 上搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6497194/

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