XElement から子孫要素を削除しようとしていましたが(.Remove()を使用)を使用していて、nullのオブジェクト参照を取得しているようですが、その理由はわかりません。属性値に基づいてXMLから要素を削除しますか?
がこのタイトル(see here)で前の質問を見たので、私はそれを削除する方法を見つけましたが、私は第一を試した方法が機能しなかった理由を私はまだ表示されません。
誰かが私を啓発できますか?
String xml = "<things>"
+ "<type t='a'>"
+ "<thing id='100'/>"
+ "<thing id='200'/>"
+ "<thing id='300'/>"
+ "</type>"
+ "</things>";
XElement bob = XElement.Parse(xml);
// this doesn't work...
var qry = from element in bob.Descendants()
where element.Attribute("id").Value == "200"
select element;
if (qry.Count() > 0)
qry.First().Remove();
// ...but this does
bob.XPathSelectElement("//thing[@id = '200']").Remove();
おかげで、 ロス
ありがとうございました。私は今問題が何かを見ています。 –