未定义类型"XmlProvider" [英] The type 'XmlProvider' is not defined

查看:82
本文介绍了未定义类型"XmlProvider"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用FSharp.Data第三方库,但在XmlProvider类上出现错误The type 'XmlProvider' is not defined.

I'm trying to use the FSharp.Data third party library but am getting an error The type 'XmlProvider' is not defined on the XmlProvider class.

namespace KMyMoney

open FSharp.Data

  module Read =

    let xml = File.ReadAllText("KMyMoneySampleFile.xml")
    type KMyMoneySource = XmlProvider<xml>

我正在使用NuGet来获取库.库为'FSharp.Data 1.1.8'

I'm using NuGet to get the library. Library is 'FSharp.Data 1.1.8'

当我键入FSharp.Data.时,给出了四个选项:CsvFreebaseOperatorsJsonRuntimeImplementation.

When I type FSharp.Data. There are four options given: Csv, FreebaseOperators, Json, and RuntimeImplementation.

我错过了什么吗?我是F#的新手.所以,对这个简单的问题感到抱歉.我看过GitHub,但没有看到任何有关此问题的信息.我正在F#中创建一个库.

Am I missing something? I'm relatively new to F#. So, sorry for the simple question. I've looked on GitHub but haven't seen any mention of this problem. I am creating a library in F#.

推荐答案

<>之间的参数是类型提供程序的Sample参数,该参数必须是编译时间常数.该示例用于推断xml的结构.

The parameter between <> is the Sample parameter of the type provider, which has to be a compile time constant. That sample is used to infer the structure of the xml.

尝试以下方法:

namespace KMyMoney

open FSharp.Data

module Read =

    type KMyMoneySource = XmlProvider<"KMyMoneySampleFile.xml">

然后做

let xml = KMyMoneySource.Load("KMyMoneySampleFile.xml")

或者如果您正在读取与XmlProvider示例参数相同的文件,请执行以下操作:

or if you're reading the same file you used as the XmlProvider sample parameter, just do this:

let xml = KMyMoneySource.GetSample() 

请注意,类型提供程序是F#3.0的功能,因此仅在VS2012或更高版本中有效.如果您使用的是VS2010,则只会遇到一堆语法错误.

这篇关于未定义类型"XmlProvider"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆