Reading value from XML file Throws an error - FAKE

2019-08-02 20:43发布

问题:

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]