XML newbie question

  • Thread starter Thread starter ORC
  • Start date Start date
O

ORC

I'm very new to XML and it's behaviour, but I'm going to use a XML file as a
persistent file store for storing configuration value between application
runs. I'm doing this for the Compact framework and because of that I'm
limited to use certain functions only. My question is: How do I create a XML
file from within my app? All the examples I've seen assumes that the XML
already exist - but what if it doesn't and my apps will have to create a
file with default values. I would be really happy if someone would help me
with a VERY simple example.

Thanks,
Ole
 
ORC said:
I'm very new to XML and it's behaviour, but I'm going to use a XML
file as a persistent file store for storing configuration value
between application runs. I'm doing this for the Compact framework
and because of that I'm limited to use certain functions only. My
question is: How do I create a XML file from within my app? All the
examples I've seen assumes that the XML already exist - but what if
it doesn't and my apps will have to create a file with default
values. I would be really happy if someone would help me with a VERY
simple example.

Thanks,
Ole

If I want to generate XML "on the fly" I usually do something like:

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlTextWriter xw = new XmlTextWriter(sw);

and then use that "xw" to write my XML.
With "sb.ToString()" I get the result in a string.
You can then write that string to a file, but it should be possible to
use another overload of XmlTextWriter to write directly to a file.
(these classes are also available in the compact framework)

Hans Kesting
 
Back
Top