Pregunta

¿Cómo consigo solo a los hijos de un XElement?

Actualmente estoy usando la función XElement.Descendants (), que devuelve todos los niveles de XElements, en lugar de solo los nodos secundarios.

Lo que realmente me gustaría es un IEnumerable de solo los niños.

¿Fue útil?

Solución

The immediate child elements of one XElement are accessible by calling the Element() or Elements() functions. Use the overloads with a name to access specific elements, or without to access all child elements.

There are also similar methods like Attribute() and Attributes() that you might find useful.

Otros consejos

XElement.Nodes() should get you what you want.

If you just want the XElement child nodes then you might need to restrict it (depending on your XML) with:

XElement.Nodes().OfType<XElement>()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top