XML提供程序无法识别标记



我正在使用XML提供程序来处理XML文件,或者我正在尝试使用它。查看以下代码:

open System
open System.IO
open System.Xml.Linq
open FSharp.Data
open System.Net
type InputXml = XmlProvider<"C:Tempsample.xml">
[<EntryPoint>]
let main argv =
    let input = InputXml.Load("C:Tempsample.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

我有编译器错误

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#samplesProgram.fs    16  27  samples

xml文件结构看起来像:

<?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>

我做错了什么?

您使用哪个版本的包?

如果我引用NuGet中的当前2.1.1XmlProvider就像一个符咒,并将节点作为属性呈现。

open System
open FSharp.Data
type InputXml = XmlProvider<"C:Tempsample.xml">
[<EntryPoint>]
let main argv =
    let input = InputXml.Load("C:Tempsample.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

最新更新