1
votes

I cannot seem to load the mortality data form the xml files hosted on the SOA website at http://mort.soa.org/

#r "../packages/FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"
#r "System.Xml.Linq.dll"
open FSharp.Data
type mortab = XmlProvider<"http://mort.soa.org/data/t1.xml">

let mtab = mortab.Load("http://mort.soa.org/data/t1.xml")

let rates = mtab.Table.Values.Axis

It does not seem to be possible to access data within the Axis element. An option to use a method GetIes is returned from intellisense, and this reports an error 'The Name of a provided type was null or empty'.

Is there any workaround for this?

2

2 Answers

0
votes

Could you try again with 2.0 prerelease? I just tested your snippet and it worked

0
votes

I've also had issues getting exactly what I want out of F# Data's XML TypeProvider. For ad-hoc work though it normally gets me close. Since the TypeProvider also gives you the XElement at each node you can always use the TypeProvider to get you almost there and just navigate the XElement and XAttributes to get you the rest of the way.

#r @"..\packages\FSharp.Data.1.1.10\lib\net40\FSharp.Data.dll"
#r "System.Xml.Linq.dll"

open FSharp.Data
open System.Linq
open System.Xml.Linq
type mortab = XmlProvider<"http://mort.soa.org/data/t1.xml">
let xname (tag:string) = XName.Get(tag)
let mtab = mortab.Load("http://mort.soa.org/data/t1.xml")

let rates = 
    mtab.Table.Values.Axis.XElement.Elements(xname "Y")
    |> Seq.map (fun e -> e.Attribute(xname "t").Value |> int, e.Value |> float)
    |> Seq.toArray