Hello All,
How to save a well formed xml string to a xml file ?
Thanks in advance...
Hi All.... I got the answer
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("WellFormedXMLString"); xmlDoc.Save(@"drive:\name.xml");
Hello All,
How to save a well formed xml string to a xml file ?
Thanks in advance...
Hi All.... I got the answer
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("WellFormedXMLString"); xmlDoc.Save(@"drive:\name.xml");
Save the string straight onto the disk. No need to convert it into XML.
Why do you need xml if it's just a string ? You could save a text file with the variabele name, and the string inside as variable value.
for example
MyTextVar1.txt would contain "MyTestSTring"
then you could get the var by:
var mystring = GetFileAsString( "MyTextVar1.txt" );
You can write any string to disk like so:
File.WriteAllText(@"c:\myfile.xml", yourXmlString);
If you have a string that is not a well-formed xml string and you want to convert that to some other format, you will have to give us some example of what you want to do.
the xml document is a text file itself. you only need to change its extension.
What's wrong with simply writing your string to disk?
using (StreamWriter writer = new StreamWriter(@"C:\file.xml"))
{
writer.Write("Xml data");
writer.Flush();
}
or if you want to "test" it:
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(data);
}
catch
{
// Fix it
}
doc.Save(@"C:\file.xml");