[英]Remove XDocument node by id
希望這對某人來說很容易解決。
我正在使用以下代碼刪除xml節點。
XDocument XD = XDocument.Parse(content);
XD.Root.Descendants("{http://www.w3.org/2000/svg}rect").Remove();
這工作正常,但我現在想在rect上執行where子句,以僅刪除ID為“ bpr”的節點。 我已經看到了包括.Where在內的一些示例,但這似乎並不想與我的代碼一起使用。
有人可以幫忙嗎?
謝謝
Foo42的答案的一種更簡單的替代(IMO):
XDocument XD = XDocument.Parse(content);
XD.Root.Descendants("{http://www.w3.org/2000/svg}rect")
.Where(el => (string) el.Attribute("id") == "bpr")
.Remove();
XDocument XD = XDocument.Parse(content);
XD.Root.Descendants("{http://www.w3.org/2000/svg}rect").Where(el => el.Attributes().Contains(at => at.Name == "id" && at.Value == "bpr")).Remove();
我認為這樣的事情應該起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.