By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

XMLdocument value changing automatically.

P: 7
I had this strange problem in handling XMLDocuments in asp.net.Though the problem occurs while working on the main application.I will try to explain it with shorter code.
I had a form with 2 buttons.The first button loads a file and second button make some changed in extracted XML node.The strange thing is that I am not touching the XMLdocument created in second button but still its getting changed.It will be more clear by seeing the examples.
The code behind for first button is :
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument xdcSettings = new XmlDocument();
string fileName = System.Configuration.ConfigurationSettings.AppSett ings.Get("RequestFilePath") + "Settings.xml";
xdcSettings.Load(fileName);
Session["Settings"] = xdcSettings;
Session["CurrentSetting"]=xdcSettings.SelectSingleNode("Settings/Setting[@id='S1']"); }

And for second button is :
protected void Button2_Click(object sender, EventArgs e)
{
XmlDocument xdcSettings = (XmlDocument)Session["Settings"];
xdcSettings.Save(@"C:\Documents and Settings\gaurav.RC\Desktop\SettingsBefore.xml");
XmlNode xdc = (XmlNode)Session["CurrentSetting"];
xdc["Elements"].InnerText = "101,102,103";
xdcSettings.Save(@"C:\Documents and Settings\gaurav.RC\Desktop\SettingsAfter.xml");
}

I am not able to understand how the variable xdcSettings in second button code is getting changed without me doing anything.The sample Settings.xml file is given as:
<Settings>
<Setting id="S1">
<Elements>101,102,103</Elements>
</Setting>
<Setting id="S2">
<Elements>5,6,7,8</Elements>
</Setting>
</Settings>
Is it because everything is being passed as reference and hance getting changed.Nevertheless still I am not sure how a standalone variable gets changed?
Nov 20 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.