Domanda

Come posso ottenere solo i figli di un XElement?

Attualmente sto usando la funzione XElement.Descendants (), che restituisce tutti i livelli di XElement, piuttosto che solo i nodi figlio.

Quello che vorrei davvero è un IEnumerable di soli bambini.

È stato utile?

Soluzione

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.

Altri suggerimenti

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>()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top