开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜