Dynamic creation of XML Elements in C#.net
Hi friends,
I created a Dynamic textbox and insert a value into XML.I send my code for u reference.
My code for XML Creation.
string sFilename = xmlpath;
XmlDocument xmlDoc = new XmlDocument();
String XmlSpecification = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
XmlSpecification = XmlSpecification + Environment.NewLine + "<Testing></Testing>";
File.AppendAllText(xmlpath, XmlSpecification);
xmlDoc.Load(sFilename);
XmlElement elmXML = xmlDoc.CreateElement("Configuration");
string strConfiguration = String.Empty;
for (int index = 0; index < 3; index++)
{
string targetTextBox = "Textbox" + index;
//Try to find the textbox
int textBoxIndex = gb.Controls.IndexOfKey(targetTextBox);
if (textBoxIndex != -1)
{
TextBox foundTextBox = (TextBox)gb.Controls[textBoxIndex];
Userprefrenece.txt1 = foundTextBox.Text;
}
String str = "port" + index.ToString();
strConfiguration = strConfiguration + Environment.NewLine + @"<str>" + Userprefrenece.txt1 + "</str>";
}
elmXML.InnerXml = strConfiguration;
xmlDoc.DocumentElement.AppendChild(elmXML);
xmlDoc.Save(sFilename);
MessageBox.Show("Saved Successfully");
I saved successfully. How can retrieve from XML. But I didn't get correct.
My XML Data
<?xml version="1.0" encoding="utf-8" ?>
- <Testing>
- <Configuration>
<str>NARAAYANAN</str>
<str>DELL</str>
<str>SUCCESS</str>
</Configuration>
</Testing>
retrieve is my problem.How can i retrieve data from xml.and store in the textbox .Please help me Urgent
Regards,
Lakshmi Narayanan.S