Question

I attached a the XmlProvider to what seems to be a valid xml (displays in IE, is validated by W3C tool)

When I write the program, everything type checks and I can compile. However at runtime I have the following error:

Data at the root level is invalid. Line 1, position 1.

When I access

  let posts = (TyPosts.Parse lastposts).GetEntries()

Where entry is a node name.

=> where should I place a breakpoint ?

I can only managed to break on the TP construction, not on its actual data access !

To reproduce the initial pb, here is a script. the only modif should be the 2 first dlls.

#r @"Z:\clones\FSharp.Data\bin\v40\FSharp.Data.dll"
#r @"Z:\clones\FSharp.Data\bin\v40\FSharp.Data.DesignTime.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll"
open System
open System.Net
open FSharp.Data
open System.IO;
open System.Text;
open System.Xml;
[<Literal>] 
let lastposts = "lastposts.xml" 
let phase0 () =
  let fetch (url : string, auth) =
   use client = new WebClient()
   client.Headers.Add("user-agent", @"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US")
   client.DownloadString url
  let write(filename, content:string) = 
     use f= new StreamWriter(filename, false)
     f.Write(content)
  let posts () = fetch(@"http://squarism.com/feed/atom/", false)
  write(  __SOURCE_DIRECTORY__   + "/"+ lastposts, posts())
phase0()

[<Literal>]
let res = __SOURCE_DIRECTORY__
type TyPosts = XmlProvider<lastposts,ResolutionFolder=res> 
let posts = (TyPosts.Parse lastposts).GetEntries() // <-- TCHETCHENIA HERE !!
Was it helpful?

Solution

What version of FSharp.Data are you using? I just tried this with 1.1.4 and it worked fine:

let feed = XmlProvider<"http://squarism.com/feed/atom/">.GetSample()
let entries = feed.GetEntries()

There was a problem with Xml namespaces that was recently fixed (see SO question)

In any case, the place to put the breakpoint is here (in the FSharp.Data.dll assembly, not FSharp.Data.DesignTime.dll assembly)

If 1.1.4 doesn't work please submit an issue on GitHub

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top