Reputation: 23
how can I get the first element
<outline title="Javascript" text="Javascript"> </outline>
from this XElement
<outline title="Javascript" text="Javascript">
<outline text="j" title="j" type="rss" xmlUrl="http://wwww.Java.com/rss2.xml"/>
</outline>
this is my code
var desireXElement =existXElement.Where(w => (string) w.Attribute("title") == "Javascript").FirstOrDefault();
Upvotes: 2
Views: 2692
Reputation: 189457
You can't select a node without that node containing its child nodes. Such a "selection" would be equivalent to a mutation. You can create a new XElement that is a copy and then mutate the new one:-
var desireElement = new XElement(existXElement.Where(w => (string)w.Attribute("title") == "Javascript").First());
desireElement.RemoveNodes();
Upvotes: 3