I have a simple xml document which looks like this.
I'm using C# and Linq to extract the value from the dayNum element of the document but
when I try to set value using my code it bombs below is the code I'm using. It all works
fine till I try to do xml.Element("dayNum").SetValue(numberValue.ToString()); I would appreciate any
assistance.
Thank you
public static int getValue()
{
XDocument xml = XDocument.Load(@"dayValue.xml");
var resultSet = from x in xml.Descendants("DayNo")
select x.Element("dayNum");
string numValue = resultSet.ElementAt(0).Value;
int numberValue = Int32.Parse(numValue);
numberValue += 1;
xml.Element("dayNum").SetValue(numberValue.ToString());
return numberValue;
}
Peter CottlePosted Jan 25, 2013, 6:32 AM
public static int getValue()
{
XDocument xml = XDocument.Load(@"dayValue.xml");
var resultSet = from x in xml.Descendants("DayNo")
select x.Element("dayNum");
string numValue = resultSet.ElementAt(0).Value;
int numberValue = Int32.Parse(numValue);
numberValue++;
xml.Root.SetElementValue("dayNum", numberValue);
xml.Save("dayValue.xml");
return numberValue;
}
VulpesPosted Jan 25, 2013, 5:34 AM