Hi,

The problem is you are using = which is the comparison operator when you should be using <- for assignment. Because you finish each line in ;; the warning you would normally receive is supressed. I have rewritten it a way that you would receive a warning if you made this mistake, and also use much less global state.

I also changed the program so it creates the xml file from scratch as I did not have the orginal XML file you were working with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#light
//Import .Net namespaces
open System.Xml;;
open System.Windows.Forms;; //For construct Form
open System.Drawing;; //For Font
open System;; //For EventHandler

//Create XmlDoc
let xmlDoc = 
    let temp = new XmlDocument()
    //Create Parent Node
    let newElem = temp.CreateElement("geral")
    temp.AppendChild(newElem) |> ignore

    //ChildNode
    let newChild = temp.CreateElement("nome")
    newChild.InnerText <- "My Text" 
    newElem.AppendChild(newChild) |> ignore

    //return created doc
    temp

let mXmlPath = "C:\\vCard.xml"
//Save Xml File
xmlDoc.Save(mXmlPath)
By on 12/2/2006 10:03 PM ()

Thanks Robert, you help me a lot. Your code is great, and simple.
And what the operator pipelines makes?

By on 12/3/2006 4:14 AM ()

The pipe operator passes the result of a function forward to another function rather that backwards. Where I wrote:

temp.AppendChild(newElem) |> ignore

You could write write this as:

ignore(temp.AppendChild(newElem))

But I think the way wrote it makes it clearer what is imporant in this line of code. The ignore function is need because the add node returns a reference to the newly added node which we do not need, without the ignore we would get a warning.

By on 12/3/2006 4:35 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