Reading value from XML file Throws an error - FAKE F#MAKE

左心房为你撑大大i 提交于 2019-12-13 17:21:01

问题


I am trying to read value from XML file from FAKE , But I am getting an error i.e.

.fsx(9,16) : eror FS000: Incomplete structurd construct at or before this
 point in expression. Expected '->' or other token.

Below is my code , I am using XMLHelper.XMLRead to read values from xml file .

#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.XMLHelper
Target "BuildMain" (fun _ ->
    for s in XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor"
        trace s)
"BuildMain"
RunTargetOrDefault "BuildMain"

Below is my XML File :

<version>
  <major number="2">
    <minor>1</minor>
    <build>1</build>
    <revised>1</revised>
  </major>
</version>

Here I am trying to read value from minor version , and moreover can I store this value in a variable so that I can use this later ??


回答1:


The for ... in construct requires either do or an arrow -> before the body:

for s in XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor" do
    trace s

You use do if the body is another loop or just side-effecting code, as in:

for x in 1..5 do
   printfn "%d" x

You use arrow -> to have the body produce a value, which then becomes part of the resulting list or sequence, as in:

let evenNumbers2to10 = [for x in 1..5 -> x*2]

The arrow -> can be viewed as a shortcut for do yield:

let evenNumbers2to10 = [for x in 1..5 do yield x*2]


来源:https://stackoverflow.com/questions/42918450/reading-value-from-xml-file-throws-an-error-fake-fmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!