tags:

views:

27

answers:

1

Hey there,

I'm having trouble with writing a System.Xml.XmlElement to disk using C# .NET.

This is what I'm trying to do at the moment and failing:

XmlWriterSettings oSettings = new XmlWriterSettings();
oSettings.Indent = true;
oSettings.OmitXmlDeclaration = false;
oSettings.Encoding = Encoding.ASCII;

XmlWriter writer = XmlWriter.Create(@"C:\xmlfile.xml", oSettings);
System.Xml.XmlElement xml = sc.WFCFunctionCall();
xml.WriteContentTo(writer2);

the variable 'xml' definitely contains valid XML, I've stopped in the debugger and inspected.

xml.WriteTo(writer2)

also does not work.

Is there a simple way of doing this?

Cheers! Nick.

+1  A: 

"Does not work" doesnt give us much to go on, but if I were to guess im thinking that you're inspecting the file right after the call to xml.WriteTo(...) and there is nothing there. You might try calling Close and/or Dispose on the XmlWriter.

Jamiec
This worked. I was using different XmlWriter objects for my different writes too so I thought they wouldn't interfere. Obviously they do! Thanks for your help on this!
Nick Cartwright