开发者

how can I get the first element of a XElement

开发者 https://www.devze.com 2023-04-09 22:57 出处:网络
how can I get the first element <outline title=\"Javascript\" text=\"Javascript\"> </outline>

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消