i got this xml code:
Code:
<formmonthnames>
<monthnames id="">January</monthnames>
<monthnames id="">February</monthnames>
<monthnames id="--">March</monthnames>
<monthnames id="">April</monthnames>
<monthnames id="">May</monthnames>
<monthnames id="">June</monthnames>
<monthnames id="">July</monthnames>
<monthnames id="">August</monthnames>
<monthnames id="--">September</monthnames>
<monthnames id="">October</monthnames>
<monthnames id="">November</monthnames>
<monthnames id="">December</monthnames>
</formmonthnames>
now im trying to figure out how to update the id attribute of those monthnames.
i got this code to retrive the nodes:
Code:
string strAttr = "";
XmlNodeList nodelist;
XmlDocument mydoc = new XmlDocument();
int i = 10;
try
{
mydoc.Load(strFilename);
nodelist = mydoc.SelectNodes("//formmonthnames//monthnames");
if (nodelist.Count > 0)
{
foreach (XmlNode fetchnode in nodelist)
{
if (fetchnode.Attributes.Count > 0)
{
strAttr = fetchnode.Attributes[0].Value;
if (strAttr != "--")
{
// update the node with the value inside i
i = i + 5;
}
}
}
}
}
catch (Exception e)
{
Response.Write = "Error: " + e.Message;
}
how do i update the node with the value of i and how do i return the updated node to the xml file?
the result should look like this:
Code:
<formmonthnames>
<monthnames id="10">January</monthnames>
<monthnames id="15">February</monthnames>
<monthnames id="--">March</monthnames>
<monthnames id="20">April</monthnames>
<monthnames id="25">May</monthnames>
<monthnames id="30">June</monthnames>
<monthnames id="35">July</monthnames>
<monthnames id="40">August</monthnames>
<monthnames id="--">September</monthnames>
<monthnames id="45">October</monthnames>
<monthnames id="50">November</monthnames>
<monthnames id="55">December</monthnames>
</formmonthnames>