Skip to content

Instantly share code, notes, and snippets.

@mavnn
Created June 24, 2015 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavnn/49fda2986c99f234a127 to your computer and use it in GitHub Desktop.
Save mavnn/49fda2986c99f234a127 to your computer and use it in GitHub Desktop.
Sometimes it's nice to be able to both experiment in FSI - and also build an executable for others to use.
#!/usr/bin/env fsharpi
(** Load up/reference some things we'll be needing. *)
#r @"packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.FscHelper
(** Set up our source files for our provider *)
let sourceFiles = [
"Validate.fsx"
]
(** Build the provider! *)
Target "BuildApp" (fun _ ->
trace "Building the build"
sourceFiles
|> Fsc (fun p -> { p with
Output = "validator.exe"
FscTarget = Exe
References = ["System.Xml"] })
)
Run "BuildApp"
#if INTERACTIVE
#r "System.Xml"
#endif
open System.Xml
open System.Xml.Schema
let readAndValidate (schema : string) (file : string) =
let schemaSet = XmlSchemaSet()
schemaSet.Add("http://15below.com/PASNGR", schema)
|> ignore
let settings = XmlReaderSettings()
settings.Schemas.Add(schemaSet)
settings.ValidationEventHandler.Add
(fun ev ->
printfn "At line %d, position %d\n%A"
ev.Exception.LineNumber ev.Exception.LinePosition ev.Message)
settings.ValidationType <- ValidationType.Schema
use reader = XmlReader.Create(file, settings)
while reader.Read() do
()
printfn "XML validation complete"
reader.Close()
#if INTERACTIVE
System.IO.Directory.SetCurrentDirectory __SOURCE_DIRECTORY__
readAndValidate "PASNGR_FlightBookingSendRequest.xsd" "Example2.xml"
#else
[<EntryPoint>]
let main args =
readAndValidate args.[0] args.[1]
0
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment