Reputation: 34099
I am using XML provider for processing xml files or I am trying to use it. Look at the following code:
open System
open System.IO
open System.Xml.Linq
open FSharp.Data
open System.Net
type InputXml = XmlProvider<"C:\Temp\sample.xml">
[<EntryPoint>]
let main argv =
let input = InputXml.Load("C:\Temp\sample.xml")
for customer in input.GetCustomers() do
for order in customer.GetOrders() do
for line in order.GetOrderLines() do
printfn "Customer: %s, Order: %s, Item: %s, Quantity: %d" customer.Name order.Number line.Item line.Quantity
Console.ReadLine() |> ignore
0 // return an integer exit code
I've got compiler error
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
The field, constructor or member 'GetCustomers' is not defined D:\f#\samples\Program.fs 16 27 samples
And the xml file structure looks like:
<?xml version="1.0" encoding="utf-8" ?>
<Customers>
<Customer name="ACME">
<Order Number="A012345">
<OrderLine Item="widget" Quantity="1"/>
</Order>
<Order Number="A012346">
<OrderLine Item="trinket" Quantity="2"/>
</Order>
</Customer>
<Customer name="Southwind">
<Order Number="A012347">
<OrderLine Item="skyhook" Quantity="3"/>
<OrderLine Item="gizmo" Quantity="4"/>
</Order>
</Customer>
</Customers>
What am I doing wrong?
Upvotes: 0
Views: 128
Reputation: 513
Which version of the package do you use?
If I reference the current one 2.1.1
from NuGet, XmlProvider
works like a charm and presents the nodes as properties.
open System
open FSharp.Data
type InputXml = XmlProvider<"C:\Temp\sample.xml">
[<EntryPoint>]
let main argv =
let input = InputXml.Load("C:\Temp\sample.xml")
for customer in input.Customers do
for order in customer.Orders do
for line in order.OrderLines do
printfn "Customer: %s, Order: %s, Item: %s, Quantity: %d" customer.Name order.Number line.Item line.Quantity
Console.ReadLine() |> ignore
0 // return an integer exit code
Upvotes: 1