This might give you an idea of what you have to do:
XmlNode productsNode = doc.CreateNode(XmlNodeType.Element, "Products",
string.Empty);
XmlNodeList itemNodes = doc.SelectNodes("//item");
foreach (XmlNode itemNode in itemNodes)
{
productsNode.AppendChild(itemNode);
itemNode.ParentNode.RemoveChild(itemNode);
}
doc.DocumentElement.AppendChild(productsNode);
that is, first create the new <Products> node, then select all nodes that
you want to move into that node, loop through them and add each node to
<Products>, then remove them from their current location.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"David Lei" <we****@online.nospam> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,
How do I add a new parent node to the existing nodes?
I have an existing XmlDocument object like this:
<item>
<something>ABC</something>
<item>
<item>
<something>DEF</something>
<item>
....
I want to add a <Products> node as its parent,
<Products>
<item>
<something>ABC</something>
<item>
<item>
<something>DEF</something>
<item>
</Products>
Thanks.
david