Link to home
Start Free TrialLog in
Avatar of techsuppoprt
techsuppoprt

asked on

Inserting Xelement in XML file before the root

Hi Experts,
Still learning LINQ and stuck on this one..
I have a pretty simple XML file:

Xdoc document = XDoc.Load("
<root>
<hi>
  <node1></node1>
  <node2></node2>
  <node3></node3>
</hi>
<hi>
  <node1></node1>
  <node2></node2>
  <node3></node3>
</hi>
</root>
");

How can I insert another <hi> XElement before before the </root>. Seems like the only options are to Add right after the <root> or as a child to the <root>.
Thank you in advance.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of techsuppoprt
techsuppoprt

ASKER

Oh nice, that was simple.

I was trying to do
document.Add(.....)
and all I had to do the name of the "root element I want to add my XElement to... makes perfect sence!
Thanks again Fernando!
Thanks again
Not a problem, always glad to help. ;=)