我将 XmlProvider 附加到似乎是有效的 xml(在 IE 中显示,由 W3C 工具验证)
当我编写程序时,所有类型都会检查并且我可以编译。但是在运行时我有以下错误:
Data at the root level is invalid. Line 1, position 1.
当我访问
let posts = (TyPosts.Parse lastposts).GetEntries()
其中 entry 是节点名称。
=> 我应该在哪里放置断点?
我只能设法打破 TP 结构,而不是它的实际数据访问!
为了重现最初的 pb,这里有一个脚本。唯一的修改应该是前 2 个 dll。
#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 !!