I'm trying to update an xml file but seem to be having problems. My xml file
is in the following format:
<main>
<site name="mysite" username="user" password="pass" />
<site ... />
</main>
The code I have is:
XDocument mydoc =
XDocument.Load( this.txtFilePat h.Text,LoadOpti ons.PreserveWhi tespace);
XElement myElem = mydoc.Elements( "site").Whe re(e =(string)
e.Attribute("na me") == fieldArray[0]).FirstOrDefaul t();
if (myElem == null) Console.WriteLi ne("myElem is null");
//myElem.SetAttri buteValue("name ",this.txtSite. Text);
myElem.Attribut e("name").Val ue = this.txtSite.Te xt;
//myElem.SetAttri buteValue("logi n", this.txtUsernam e.Text);
myElem.Attribut e("login").Valu e = this.txtUsernam e.Text;
//myElem.SetAttri buteValue("pass word", this.txtPasswor d.Text);
myElem.Attribut e("password").V alue = this.txtPasswor d.Text;
It doesn't seem to be working. myElem variable seems to be null. Any
suggestions?
--
TC
is in the following format:
<main>
<site name="mysite" username="user" password="pass" />
<site ... />
</main>
The code I have is:
XDocument mydoc =
XDocument.Load( this.txtFilePat h.Text,LoadOpti ons.PreserveWhi tespace);
XElement myElem = mydoc.Elements( "site").Whe re(e =(string)
e.Attribute("na me") == fieldArray[0]).FirstOrDefaul t();
if (myElem == null) Console.WriteLi ne("myElem is null");
//myElem.SetAttri buteValue("name ",this.txtSite. Text);
myElem.Attribut e("name").Val ue = this.txtSite.Te xt;
//myElem.SetAttri buteValue("logi n", this.txtUsernam e.Text);
myElem.Attribut e("login").Valu e = this.txtUsernam e.Text;
//myElem.SetAttri buteValue("pass word", this.txtPasswor d.Text);
myElem.Attribut e("password").V alue = this.txtPasswor d.Text;
It doesn't seem to be working. myElem variable seems to be null. Any
suggestions?
--
TC
Comment