How to get elements by name in XML using LINQ

后端 未结 2 1131
暗喜
暗喜 2021-01-04 05:41

I\'ve chosen the title here as my problem is I need to get the Item nodes mentioned in the example. I have the following XML and am having problems using LINQ to query it, I

2条回答
  •  粉色の甜心
    2021-01-04 06:35

    Assuming element is your element:

    var ids = element.Element("items")
                     .Elements("item")
                     .Select(item => item.Element("id").Value);
    

    The Element and Elements methods return only direct children, not all descendants, so it doesn't return the element which is under

提交回复
热议问题