I have the following XElement:
<Assembly name="3">
<Component name="2" />
</Assembly>
I would like to get just the root element. <Assembly name="3"> I cant see any method which suits for me.
XElement.????? I cant find XElement.Root;
Does any clue?
You could call
RemoveNodeson it… create a copy first if you need to preserve the original content for other reasons.It’s not really clear what you’re trying to do with this. The element logically contains all its children – there’s no concept of
XElement.Rootbecause an element “is itself”.RemoveNodeswill remove all the child nodes, but if you just want to get the name of the element, or its attributes, you can do that without changing the structure at all.