gpt4 book ai didi

f# - 读取 Xml 文件会引发错误 - FAKE F#MAKE

转载 作者:行者123 更新时间:2023-12-01 23:40:21 24 4
gpt4 key购买 nike

我正在使用 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
)

最佳答案

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

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

看起来您正在指定 failOnErrorxmlFileNamenameSpace 参数*,但您没有指定最后两个字符串参数。由于 F# 使用 partial application ,这意味着您从 XMLRead 调用中返回的是一个正在等待另外两个字符串参数的函数(因此 string -> string -> (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 文件。

关于f# - 读取 Xml 文件会引发错误 - FAKE F#MAKE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42919797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com