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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again
Not a problem, always glad to help. ;=)
ASKER
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!