Over-writing an XML attribute?
<?
<eTrackerstatus="on"/>
<?
<eTrackerstatus="on"/>
You would need to use the XmlDocument class for overwriting the values.
Please find below the code snippet for overwriting the value of the attribute.
private void Form1_Load(object sender, EventArgs e)
CODE SNIPPET
{
string strXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><eTracker status=\"on\" />";
XmlDocument objXmlDoc = new XmlDocument();
objXmlDoc.LoadXml(strXml);
objXmlDoc.DocumentElement.Attributes["status"].Value = "off";
MessageBox.Show(objXmlDoc.DocumentElement.Attributes["status"].Value);
}
The code sample was written in VS2005 Beta2 - should work fine for .NET 1.1 as well.
Regards,
Vikram
Thanks for this, but the xml file already exists on the server.. how can i read/write to it..?
A small change would do that : private void Form1_Load(object sender, EventArgs e)
CODE SNIPPET
{
string strFilePath = @"C:\MyXml.xml";
XmlDocument objXmlDoc = new XmlDocument();
objXmlDoc.Load(strFilePath);
objXmlDoc.DocumentElement.Attributes["status"].Value = "off";
objXmlDoc.Save(strFilePath);
}
The code sample was written in VS2005 Beta2 - should work fine for .NET 1.1 as well.
Regards,
Vikram