我正在尝试将两个XmlDocument.xml
组合用于WebAPI 2.0文档。但是当我执行下面的代码时,它返回< /doc>
没有错误。看起来我做的一切都很正确,所以我有点困惑。 printf
语句所在的位置,即结果值失败的位置。代码之前和之后似乎完美无缺。
#r "../packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll"
#r "System.Xml.Linq.dll"
open FSharp.Data
open System.IO
// Define your library scripting code here
let seedPath = __SOURCE_DIRECTORY__ + "../../FieldOps/bin"
let outFile = __SOURCE_DIRECTORY__ + "../../FieldOps/App_Data/XmlDocument.xml"
type XmlDocument = XmlProvider<"""<?xml version="1.0"?>
<doc>
<assembly><name>lala</name></assembly>
<members>
<member name="">
<summary>lala</summary>
<param name="">lala</param>
<param name="">lala</param>
<returns>lala</returns>
</member>
<member name=""></member>
</members>
</doc>
""">
let xmlPaths =
[
"../bin/Release"
]
let seed = XmlDocument.Load(Path.Combine(seedPath, "XmlDocument.xml"))
let addFile path = Path.Combine(path, "XmlDocument.XML")
let loadXmlDoc (path: string) = XmlDocument.Load(path)
let joinXmlDocuments (acc: XmlDocument.Doc) path =
let doc = (addFile >> loadXmlDoc) path
let members = Array.append acc.Members doc.Members
let result = new XmlDocument.Doc(acc.Assembly, members)
printf "result ------------------- %A --------------------" result
result
let joinedDocs =
xmlPaths
|> List.fold (joinXmlDocuments) seed
let xml = joinedDocs.XElement.ToString()
File.WriteAllText(outFile, xml)
答案 0 :(得分:1)
更新→我想我知道为什么会出现这个问题。可能是因为它们是不可变的,所以你需要创建一个新的。但是,如何轻松地做到这一点,我不知道。
XmlProvider
似乎无法识别它自己的类型。不确定到底发生了什么。但是,当我从头开始重新创建类型时,它并没有返回我看到的空< /doc>
值。
这是我最终做的事情:
let assembly = new XmlDocument.Assembly(acc.Assembly.Name)
let members =
Array.append acc.Members doc.Members
|> Array.map
(
fun x ->
let parameters =
x.Params
|> Array.map (fun x -> new XmlDocument.Param(x.Name, x.Value))
new XmlDocument.Member(x.Name, x.Summary, parameters, x.Returns)
)
let result = XmlDocument.Doc(assembly, members)
答案 1 :(得分:1)
这已在F#Data 2.3.0-beta1中修复