【问题标题】:Reading Xml file throws an error - FAKE F#MAKE读取 Xml 文件会引发错误 - FAKE F#MAKE
【发布时间】:2017-03-21 06:23:03
【问题描述】:

我正在使用XMLHelper.XMLRead 读取 FAKE 脚本中的 XML 文件,但它会引发错误,即

The type '(string -> string ->seq<string>)' is not a type whose value can be enumerated with this syantax , i.e. is not compatible with either seq<_>,IEnumerable<_> or IEnumerable and does not have a GetEnumerator method

下面是我的代码:

let x = XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor" 
Target "New" (fun _ ->
    for i in x do
        printf "%s" i
)

【问题讨论】:

  • 您正在返回一个部分应用的函数并尝试枚举它。您可能需要更多 XMLRead 参数。

标签: f# f#-interactive f#-3.0 f#-data f#-fake


【解决方案1】:

如果您查看API documentation for XMLHelper,您会看到XMLRead 的函数签名如下所示:

failOnError:bool -> xmlFileName:string -> nameSpace:string -> prefix:string -> xPath:string -> seq<string>

您似乎指定了failOnErrorxmlFileNamenameSpace 参数*,但您没有指定最后两个字符串参数。由于 F# 使用 partial application,这意味着您从 XMLRead 调用中得到的是一个正在等待另外两个字符串参数的函数(因此您得到的错误消息中的 string -&gt; string -&gt; (result) 函数签名)。

* 您可能打算让"/version/major/minor" 填充xPath 参数,但F# 按给定顺序应用参数,因此它填充了第三个参数,即nameSpace

要解决此问题,请指定 XMLRead 期望的所有参数。我查看了 XMLRead 源代码,如果您没有在输入文档中使用 XML 命名空间,nameSpaceprefix 参数应该是空字符串。所以你想要的是:

let x = XMLHelper.XMLRead true "D:/test/Version.Config" "" "" "/version/major/minor" 
Target "New" (fun _ ->
    for i in x do
        printf "%s" i
)

顺便说一句,既然我已经查看了 your other question,我想你会想要 XMLHelper.XMLRead_Int 函数:

let minorVersion =
    match XMLHelper.XMLRead_Int true "D:/test/Version.Config" "" "" "/version/major/minor" with
    | true, v -> v
    | false, _ -> failwith "Minor version should have been an int"

一旦您的代码超过该行,您的 minorVersion 中就有一个 int,或者您的构建脚本已抛出错误并退出,以便您可以修复您的 Version.Config 文件。

【讨论】:

  • 谢谢你 rmunn :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 1970-01-01
相关资源
最近更新 更多