Created
June 24, 2015 10:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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