how can I get the first element of a XElement
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" 开发者_Python百科xmlUrl="http://wwww.Java.com/rss2.xml"/>
</outline>
this is my code
var desireXElement =existXElement.Where(w => (string) w.Attribute("title") == "Javascript").FirstOrDefault();
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();
精彩评论