A
Alan Silver
Hello,
I have a site that stores some info in an XML file. The file is pretty
simple, of the form...
<Site>
<SiteName>Fred's Ferrets</SiteName>
<SomeVar>Whatever</SomeVar>
.... etc ...
</Site>
So far I have just used a simple routine to read values from the file...
public string SiteVars(string varName) {
DataSet dstSiteVars = new DataSet();
dstSiteVars.ReadXml(Server.MapPath("/") + @"\Site.xml");
XmlDataDocument xddSiteVars = new XmlDataDocument(dstSiteVars);
XmlNodeList xnlSiteVars = xddSiteVars.GetElementsByTagName(varName);
if (xnlSiteVars.Count == 1) {
return xnlSiteVars.Item(0).InnerText;
} else {
return "";
}
}
This is fine, but now I want to be able to update/add values. I have
looked around a bit, but all the code is so complex that I can't help
but feel that it's OTT for what I need.
Basically I would like to write a companion method for the above...
public void UpdateSiteVar(string varName, string newValue) {
....
}
That when called would either update the existing value if it exists, or
add the new node/value to the file if it doesn't already exist.
Can anyone help me here please? I'm sure it's really simple, but I'm
getting swamped with large examples.
TIA
I have a site that stores some info in an XML file. The file is pretty
simple, of the form...
<Site>
<SiteName>Fred's Ferrets</SiteName>
<SomeVar>Whatever</SomeVar>
.... etc ...
</Site>
So far I have just used a simple routine to read values from the file...
public string SiteVars(string varName) {
DataSet dstSiteVars = new DataSet();
dstSiteVars.ReadXml(Server.MapPath("/") + @"\Site.xml");
XmlDataDocument xddSiteVars = new XmlDataDocument(dstSiteVars);
XmlNodeList xnlSiteVars = xddSiteVars.GetElementsByTagName(varName);
if (xnlSiteVars.Count == 1) {
return xnlSiteVars.Item(0).InnerText;
} else {
return "";
}
}
This is fine, but now I want to be able to update/add values. I have
looked around a bit, but all the code is so complex that I can't help
but feel that it's OTT for what I need.
Basically I would like to write a companion method for the above...
public void UpdateSiteVar(string varName, string newValue) {
....
}
That when called would either update the existing value if it exists, or
add the new node/value to the file if it doesn't already exist.
Can anyone help me here please? I'm sure it's really simple, but I'm
getting swamped with large examples.
TIA