Reputation: 3478
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");
Upvotes: 0
Views: 6662
Reputation: 22950
The xml document is a text file itself. you only need to change its extension.
Upvotes: 0
Reputation: 9661
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");
Upvotes: 1
Reputation: 121037
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.
Upvotes: 1
Reputation: 3035
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" );
Upvotes: 0
Reputation: 43217
Save the string straight onto the disk. No need to convert it into XML.
Upvotes: 0