[英]XML Provider does not recognize tags
我正在使用XML提供程序來處理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>
我究竟做錯了什么?
您使用哪個版本的軟件包?
如果我從NuGet引用當前的2.1.1
,則XmlProvider
就像一個XmlProvider
一樣工作,並將節點顯示為屬性。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.