The problem with your code is xw is not in scope when you try and use it. You want to say something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
#light
open System.IO
open System.Xml
open System.Text

let main() = 
    let file = File.Create("c:\\out.xml")
    let xml = "<xml />"
    let xw = new XmlTextWriter(file, Encoding.Unicode)
    xw.Formatting <- Formatting.Indented;
    xw.WriteString(xml)
    
do main()
By on 7/10/2008 12:03 AM ()

ok. It was fault because I didn't indent the code properly in my post. But my F# script is correctly indented and the problem persists.

Thanks.

By on 7/10/2008 3:02 AM ()

Arrh, okay. There's a couple of problems with the code I posted. You need to close both the file and the text writer to ensure they are disposed. Also the text writer is designed to be used to write elements indivdually. The easiest way to correct this is to pass by the DOM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#light
open System.IO
open System.Xml
open System.Text

let main() = 
    use file = File.Create(@"C:\Documents and Settings\rpickering\My Documents\Visual Studio 2008\Projects\TestWriteXML\test.xml")
    let xml = "<xml><toto>tete</toto></xml>"
    let doc = new XmlDocument()
    doc.LoadXml(xml)
    use xw = new XmlTextWriter(file, Encoding.UTF8)
    xw.Formatting <- Formatting.Indented;
    doc.WriteTo(xw)
    
do main()
By on 7/10/2008 5:18 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper