Jump to content

XML/DOM serialization: Difference between revisions

Added F# version
(Added F# version)
Line 231:
 
(On the use of <tt>&lt;unsafe></tt>: The class has not yet been reviewed for E safety, so <tt>&lt;import:...makeDocumentBuilderFactory></tt> is not yet allowed. The review would probably be straightforward.)
 
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open System.Xml
 
[<EntryPoint>]
let main argv =
let xd = new XmlDocument()
// Create the required nodes:
xd.AppendChild (xd.CreateXmlDeclaration("1.0", null, null)) |> ignore
let root = xd.AppendChild (xd.CreateNode("element", "root", ""))
let element = root.AppendChild (xd.CreateElement("element", "element", ""))
element.AppendChild (xd.CreateTextNode("Some text here")) |> ignore
// The same can be accomplished with:
// xd.LoadXml("""<?xml version="1.0"?><root><element>Some text here</element></root>""")
 
let xw = new XmlTextWriter(System.Console.Out)
xw.Formatting <- Formatting.Indented
xd.WriteContentTo(xw)
0</lang>
Output
<pre><?xml version="1.0"?>
<root>
<element>Some text here</element>
</root></pre>
 
=={{header|Fantom}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.