Re: Replacing XML Elements programmatically with either VB.Net or C#

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



This code is for retrieval:

XmlDocument xdoc = new XmlDocument();
string strXML = "<Root_Element><Topic
index=\"1\"><Sub_Topic><Notes>";
strXML += "</Notes><Notes></Notes></Sub_Topic></Topic>";
strXML += "<Topic index=\"2\"><Sub_Topic><Notes></Notes>";
strXML += "<Notes></Notes><Notes></Notes></Sub_Topic><Sub_Topic>";
strXML += "<Notes></Notes></Sub_Topic></Topic><Topic index=\"3\">";
strXML +=
"<Sub_Topic><Notes></Notes></Sub_Topic></Topic></Root_Element>";
xdoc.LoadXml(strXML);
while(xdoc.HasChildNodes)
{
for(int i = 0; i < xdoc.SelectNodes("/Root_Element/").Count; i++)
{
if(xdoc.GetElementsByTagName("Topic")[i].Attributes[0].Value.ToString().Equals("2"))
{
/* Now Replace the childNodes */
}
}
}

.