<namespace>
<root>
<node1>
<element 1>
<element 1>
</node1>
<node2>
<element 1>
<element 1>
</node2>
</root>
string stringContains = string.Empty;
foreach(string line in File.ReadLines(Path))
{
if(line.Contains("<Root>"))
{
stringContains = line.Replace("<Root>", "<Root>" + newelement.OuterXml);
}
}
File.AppendAllText(Path, stringContains);
I must replace root
with other nodes,
so that i am appending text. However the above code appends existing text with stringContains