Hi Folks,
I have come across a behaviour which seems strange to me.
I wrote the following code for a task:
-----BEGIN CODE-------
XmlDocument idc = new XmlDocument();
idc.LoadXml("<book><title>The Confidence
Man</title><first-name>Herman</first-name><last-name>Melville</last-name></book>");
XmlNode nd = idc.SelectSingleNode("/book");
XmlNode krs = idc.CreateElement("hello");
foreach (XmlNode cl in nd.ChildNodes)
{
Console.WriteLine(cl.Name + " : " + cl.InnerText);
krs.AppendChild(cl);
}
foreach (XmlNode ct in krs.ChildNodes)
{
Console.WriteLine(ct.Name + " : " + ct.InnerText);
}
Console.ReadLine();
return;
-----END CODE-----
I expected the code to copy the child nodes of "book" node to the
"hello" node.
Instead, only the first child of "book" was appended to "hello" node
bcoz, the foreach loop quits after first iteration.
Am i missing anything?
TIA
Sek.