#r "System.Data"
#r "System.Xml"
#r "System.Xml.Linq"
#r "../packages/FSharp.Data.2.2.3/lib/net40/FSharp.Data.dll"
open FSharp.Data
open System.IO
type t = XmlProvider<"./paymentsample.xml">
let dir = __SOURCE_DIRECTORY__ + "/files"
let files = Directory.EnumerateFiles dir
for f in files do
let x = t.Load f
for pay in x.Body.PaymentBatch.Payments do
printfn "%A" pay
gives this stacktrace:
System.Xml.XmlException: Document element did not appear. Line 1, position 1.
at Mono.Xml2.XmlTextReader.Read () [0x00000] in :0
at System.Xml.XmlTextReader.Read () [0x00000] in :0
at Mono.Xml.XmlFilterReader.Read () [0x00000] in :0
at System.Xml.Linq.XDocument.ReadContent (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in :0
at System.Xml.Linq.XDocument.LoadCore (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in :0
at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader, LoadOptions options) [0x00000] in :0
at System.Xml.Linq.XDocument.Parse (System.String text, LoadOptions options) [0x00000] in :0
at System.Xml.Linq.XDocument.Parse (System.String text) [0x00000] in :0
at FSharp.Data.Runtime.BaseTypes.XmlElement.Create (System.IO.TextReader reader) [0x00000] in :0
at FSI_0002+results@15.GenerateNext (IEnumerable1& next) [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[System.Boolean].MoveNextImpl () [0x00000] in :0
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[System.Boolean].System-Collections-IEnumerator-MoveNext () [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Collections.SeqModule.ToList[Boolean] (IEnumerable1 source) [0x00000] in :0
at <StartupCode$FSI_0002>.$FSI_0002.main@ () [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
Running this script in FSI in Xamarin Studio:
gives this stacktrace:
Note that this code works fine on Windows/.Net.
Sample xml: