XML Provider无法识别标签

时间:2015-02-18 15:33:47

标签: xml f# f#-data

我正在使用XML provider来处理xml文件,或者我正在尝试使用它。 请查看以下代码:

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

我有编译错误

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

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>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您使用的是哪个版本的套餐?

如果我从NuGet引用当前的2.1.1XmlProvider就像一个魅力,并将节点显示为属性。

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