Help editing Xml file in C#
-
Hi I'm trying to modify an Xml file. This is the content of the Xml. The problem is that after changes, it will creates a copy of the content of the Xml file without changing the old content. Before changes :
After changes :
The code is :
//xml document object System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); FileStream reader = new FileStream(this.\_XmlFilePath, FileMode.Open, FileAccess.ReadWrite); xdoc.XmlResolver = null; //load the xml file xdoc.Load(reader); System.Xml.XmlElement Node = (System.Xml.XmlElement)xdoc.DocumentElement.SelectSingleNode("//configuration/connectionStrings/add\[@name=\\"Application.Properties.Settings.DBConnectionString\\"\]"); if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file xdoc.Save(reader); reader.Close(); }
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
-
Hi I'm trying to modify an Xml file. This is the content of the Xml. The problem is that after changes, it will creates a copy of the content of the Xml file without changing the old content. Before changes :
After changes :
The code is :
//xml document object System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); FileStream reader = new FileStream(this.\_XmlFilePath, FileMode.Open, FileAccess.ReadWrite); xdoc.XmlResolver = null; //load the xml file xdoc.Load(reader); System.Xml.XmlElement Node = (System.Xml.XmlElement)xdoc.DocumentElement.SelectSingleNode("//configuration/connectionStrings/add\[@name=\\"Application.Properties.Settings.DBConnectionString\\"\]"); if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file xdoc.Save(reader); reader.Close(); }
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
yes it suppose to do, because you are saving the xml in same stream. try this
if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file **_reader.Position = 0;_** xdoc.Save(reader); reader.Close(); }
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
yes it suppose to do, because you are saving the xml in same stream. try this
if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file **_reader.Position = 0;_** xdoc.Save(reader); reader.Close(); }
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
hi thanks for the answer..it partially solved the problem. now the result is :
tem.Data.OleDb" />
this part is wrong :
tem.Data.OleDb" />
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
-
hi thanks for the answer..it partially solved the problem. now the result is :
tem.Data.OleDb" />
this part is wrong :
tem.Data.OleDb" />
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
okay do this
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); xdoc.XmlResolver = null; //load the xml file xdoc.Load(this.\_XmlFilePath); System.Xml.XmlElement Node = (System.Xml.XmlElement)xdoc.DocumentElement.SelectSingleNode("//configuration/connectionStrings/add\[@name=\\"Application.Properties.Settings.DBConnectionString\\"\]"); if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file xdoc.Save(this.\_XmlFilePath); }
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
okay do this
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); xdoc.XmlResolver = null; //load the xml file xdoc.Load(this.\_XmlFilePath); System.Xml.XmlElement Node = (System.Xml.XmlElement)xdoc.DocumentElement.SelectSingleNode("//configuration/connectionStrings/add\[@name=\\"Application.Properties.Settings.DBConnectionString\\"\]"); if (Node != null) { //key found, set the value Node.Attributes.GetNamedItem("Source").Value = "C:\\DataDabe\\DB.mdb"; //finally, save the new version of the config file xdoc.Save(this.\_XmlFilePath); }
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can