Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Last active December 15, 2015 07:29
Show Gist options
  • Save vasily-kirichenko/5223371 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/5223371 to your computer and use it in GitHub Desktop.
FSharp.Data XML Type Provider vs FSharpx one
open FSharp.Data
open FSharpx
[<Literal>]
let xml = """<?xml version="1.0" encoding="utf-8"?>
<response list="true">
<count>7</count>
<message>
<body>Hello!</body>
<mid>10850</mid>
<from_id>62912577</from_id>
<date>1268215527</date>
<read_state>0</read_state>
<out>1</out>
</message>
<message>
<body>Hello!!</body>
<mid>10848</mid>
<from_id>5005272</from_id>
<date>1268215303</date>
<read_state>1</read_state>
<out>0</out>
</message>
</response>"""
// FSharp.Data
type Xml = XmlProvider<xml>
let sample = Xml.GetSample().GetMessages()
|> Seq.map (fun msg -> msg.Body, msg.Date) // beautiful!
|> Seq.toList
// FSharpx
type Xmlx = StructuredXml<Schema = xml>
let samplex = Xmlx().Root.GetMessages()
|> Seq.map (fun msg -> (msg.GetBodies() |> Seq.head).Element.Value, // this is just ugly
(msg.GetDates() |> Seq.head).Element.Value) // and there're no types at all...
|> Seq.toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment