XElement has something like XmlNodeList

I want to do this using XElement:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

mlNodeList nodeList = doc.GetElementsByTagName("Title");

and get all the nodes. Is it possible?

+3
source share
1 answer

Equivalent to your code:

XElement doc = XElement.Parse(xml);
IEnumerable<XElement> nodeList = doc.Descendants("Title");

You can call nodeList.ToList()if you need a discrete list, but if you just want to iterate, it IEnumerableshould be fine.

Edit: There are two ways to select nodes. Use Elements()if you need immediate children from node, or use Descendants()if you need all the children, no matter how deep they are.

+6
source

Source: https://habr.com/ru/post/1776950/


All Articles