My C # is a little disturbing and I've never written XML with it before. If I try to write anything other than elements, then I am having trouble typing in a file. Here is the test code I:
var guiPath = txtGuiPath.Text; MessageBox.Show ("dumping file:" + GUIPath); Try {var author = new XmlTextWriter ("client_settings.xml", tap); Author.WriteStartDocument (); Author. White comment ("Generation configuration created on 01/01/01"); Author.WriteStartElement ("config"); Author.WriteStartElement ("GuiPath"); Writer.WriteString (guiPath); Writer.WriteEndElement (); Writer.WriteEndElement (); Writer.WriteEndDocument (); Writer.Close (); } Hold (Exception pre) {Message Box. Show (ex.Message); MessageBox.Show ("End Dumping");
If Gypath is empty then I get the following XML:
But if a text is inside Ghiapath then the file is not written anything. I can also remove the client_settings.xml file and fire this code as much as possible and the xipl file is never ready unless the geipath is empty. Some passes such as "It is a test" to write works also.
Update
Since I'm trying to write a system path, that problem seems to be if I delete all the backslash then the resulting string Will write correctly, but if I pass a string or WriteCData that I write it then the XML will not be written at all.
Update 2
It indicates that I had so many problems because the XML file, which was set on the path Geopath, that directory Was not there in the app (it seemed to me that all was not being produced). Therefore, if I had set Gypath to 'C: \ program files at externalApp \ appName.exe', then instead of the startup folder for this app, XML file as 'C: \ Program Files: externalApp \ client_settings.xml' Was saving. . Why, I do not know I had started applying the application. StartupPath and added that file name and it now works great.
Thanks for all help!
You may want to test the API in System.Xml.Linq. This is a more flexible approach to creating and writing XML, writing your document can be done almost like this:
XDocument document = new XDocument (); Document.Add (New XComment ("Configuration Generated on 01/01/01")); Document.Add (New XElement ("Config", New XElement ("GuiPath", Gypath)); // var xmlWriter = new XmlTextWriter ("client_settings.xml", tap); // document.WriteTo (xmlWriter); // XDocument.Save () Thanks to Barry Kelly for pointing the document. Save ("client_settings.xml");
Comments
Post a Comment