Giter Club home page Giter Club logo

fsharp.data.xsd's Introduction

FSharp.Data.Xsd

NuGet Badge Travis build status

FSharp.Data.Xsd augments the XML type provider of F# Data with schema support.

XML is in decline but many enterprises still use it heavily. That's why a type provider with schema support may help popularizing F# as a great tool also for boring line of business applications (BLOBAs).

Project status and Roadmap

This project is no longer maintained because XSD support is now available in F# Data version 3.0.0.

Maintainer(s)

The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)

fsharp.data.xsd's People

Contributors

chrsteinert avatar giacomociti avatar jannickj avatar sergey-tihon avatar thorium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fsharp.data.xsd's Issues

"No suitable element definition found in the schema." for SQL Server Schema

Description

The type provider 'ProviderImplementation.XmlProvider' reported an error: No suitable element definition found in the schema.

Repro steps

  1. Create an XMLProvider Schema (for the file)[http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd]. Like so
type XMLResultType = XmlProvider<Schema = """
{{Content of file above}}
""">

Expected behavior

That the library could parse and understand the schema file.

Actual behavior

Error described in Description.

Known workarounds

None.

Related information

  • Windows 10 Pro
  • 1709
  • .NET Framework 4.6.1 - F# runtime - 4.4.3.0

problems with the NuGet package (missing Xml libs and wrong version of FSharp.Core)

repro:

With Visual Studio 2015 I created a new F# Console Application, targeting .NET framework 4.6.

Installed package FSharp.Data.Xsd.0.0.2 (using menu 'Manage NuGet packages...' in project references).

This also installed FSharp.Core.3.0.2 as a dependency.
Notice that the output from Package Manager include this:
Attempting to resolve dependencies for package 'FSharp.Data.Xsd.0.0.2' with DependencyBehavior 'Lowest'

Even simple code (like that given as example in the website) initially won't compile because of missing references to the BCL libraries for Xml.
After referencing System.Xml and System.Xml.Linq it compiles but then it breaks at runtime:

Unhandled Exception: System.MissingMethodException: Method not found: 'Microsoft.FSharp.Core.FSharpOption`1<System.String> FSharp.Data.Runtime.XmlRuntime.TryGetValue(FSharp.Data.Runtime.BaseTypes.XmlElement)'.
   at Program.main(String[] argv)
Press any key to continue . . .

This is clearly due to the version of FSharp.Core.
I read often about it, for example here and here but still I'm quite confused about this topic.

To fix things I added a binding redirect like this in the app.config:

<runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
  </dependentAssembly>
 </assemblyBinding>
</runtime>

But clearly this is a workaround.

There's something wrong in the way FSharp.Data.Xsd is built and packaged.
Missing Xml references is a minor issue but the FSharp.Core stuff is much more concerning.

nillable=true causes the data type to be misread

Description

In the following XSD snippet in partiesFile.xsd:

<xs:complexType name="passportType">
    <xs:sequence>
        <xs:element nillable="true" name="PassportCountry" type="xs:string"/>
        <xs:element nillable="true" name="PassportNumber" type="xs:string"/>
        <xs:element nillable="true" name="PassportExpirationDate" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

I read partiesFile in with the following code:

type partiesSchema = XmlProvider<Schema = PartiesFile>
type passport = partiesSchema.Passport

Hover over Passport in VS2017 and it says:

type Passport =
inherit XmlElement
new: passPortCountry: PassportCountry * passportNumber: PassportNumber * passportExpirationDate: PassportExpirationDate -> Passport + 1 overload
member PassportCountry: PassportCountry
member PassportExpirationDate: PassportExpirationDate
member PassportNumber : Passport Number

In short, it's reading the name attribute as the type and ignoring the type="xs:string".

These were the only ones in the schema that had nillable="true" as attributes. When I removed these, it correctly recognized them as string types.

Position of the attribute doesn't seem to matter. I tried:
<xs:element name="PassportCountry" type="xs:string" nillable="true" />

This still didn't work.

Expected behavior

Declared types are recognized despite the presence of the nillable attribute

  • Windows10
  • master
  • .NET 4.5.2, Fsharp.Core 4.4.0.0

Support XML schema list

Description

Currently a xs:list parses to its base type

Repro steps

  1. Unzip FSharp.Data.Xsd_issue.zip

  2. See the error in the .fsx on od and Some id

Expected behavior

The constructor accepts float list for od and Some float list for id.

Actual behavior

The constructor accepts float for od and Some float for id.

Known workarounds

No idea.

Related information

  • Operating system: Windows 10 Home; Version 1607; Build 14393.1480
  • Branch: NuGet package v1.0.0
  • .NET Runtime, CoreCLR or Mono Version: .NET framework 4.5.2, F# runtime 4.0

Feature: Allow sequences or arrays for generated types

Description

Currently, the constructors for generated types on repeating elements is an array. It would be nice if it can be sequences so the data can be streamed without possibly loading huge data structures in memory.

Support substitution groups

Substitution groups are currently ignored. This means that a certain element may in fact
be missing - even if mandatory - in a perfectly valid document. The alternative elements in place of it are
still available through the untyped api, but they can easily go unnoticed.
Worse, an exception is raised attempting to access the typed property for a missing element.

A possible design to support substitution groups, is to consider them a kind of Choice,
hence providing separate optional properties for each alternative found in the schema.

While doable, this certainly requires a certain effort, only worth if this feature is used frequently
enough in real world schemas.

Lazy Streaming?

Description

We tend to work with super big XML files and it would be so nice to be able to stream them lazily with this.

Repro steps

No problem, just a suggestion

Expected behavior

Actual behavior

So I think an IEnumerable with a bunch of optional components for all of the top level types would work, I'm up for anything here.

Known workarounds

Buy more ram

Related information

  • Operating system
  • Branch
  • .NET Runtime, CoreCLR or Mono Version
  • Performance information, links to performance testing scripts

New "xs:date" XSD types are including time info from .NET DateTime values

Description

If an XSD schema document has an element or attribute that is defined as "xs:date" type, the FSharp.Data.Xsd library puts DateTime values ("xs:dateTime") instead of date-only values.

Please note that I am explicitly referring to the MySchemaType.MyElement(prop1 = someValue;) method of creating objects. In this case, if prop1 is defined in the XSD as "xs:date", passing a .NET DateTime value in will result in the XElement being created with date and time information...when, acccording to the XSD document, it should be only a date value.

When creating new objects using MySchemaType.MyElement(XElement) works correctly...but only if the XElement already has the correct syntax (i.e., uses a Date-only value rather than DateTime value). I do not necessarily expect that the library will fix invalid XElement values in this situation, although it might be nice to raise some sort of warning. Overall, I expect the library to adhere to the type definitions in the XSD document and inserting date+time when the XSD explicitly defines date-only values is incorrect behavior.

Repro steps

#r "System.Xml.Linq.dll"
#r "FSharp.Data.Xsd.dll"

open System
open FSharp.Data

type Sample = XmlProvider<Schema = """
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="foo">
      <xs:complexType>
        <xs:attribute name="baz" type="xs:date" />
      </xs:complexType>
    </xs:element>
  </xs:schema>""">

let createUsingProps : Sample.Foo = Sample.Foo( DateTime.Now.Date |> Some )
let createUsingXelement : Sample.Foo = Sample.Parse """<foo baz="2018-05-02" />"""


createUsingProps.XElement |> sprintf "Using props method:\n%A"
createUsingXelement.XElement |> sprintf "Using XElement method:\n%A"

(*
> 
val it : string =
  "Using props method:
<foo baz="2018-05-02T00:00:00.0000000-04:00" />"
> 
val it : string = "Using XElement method:
<foo baz="2018-05-02" />"
> 
*)

Expected behavior

That the library would use the"xs:date" type defined in the XSD document when creating new objects.

Actual behavior

The library actually uses a "xs:datetime" type when creating new objects using properties.

Known workarounds

Creating new objects using MySchemaType.MyElement(XElement) works correctly...but only if the XElement already has the correct syntax (i.e., uses a Date-only value rather than DateTime value).

Related information

  • .NET Framework: 4.5.2
  • FSharp.Data.Xsd: 1.0.2.0
  • Windows 10 operating system

Support for recursive schemas

The current behavior in case of recursion is to provide a type with no properties.
This allows at least to access recursively nested elements with the untyped XElement api (and retaining typed access for the rest of the elements in the schema).
A better option may be to fully support recursion; The XML provider in FSharp.Data has a global inference mode that unifies elements with the same name.
Maybe we can somehow take advantage of this mechanism.

0...n relationship in .xsd

Hi,

First of all, thank you for this library, it's very helpful !

I am a perfect newbie to coding and github so please accept all my apologies if I make mistakes or misuse in the following attempt.

I think I've an issue with XmlProvider and my .xsd scheme.

In my .xsd I have a Node "Reason" that is descendant of the Node "Point" with attributes minOccurs = 0 and maxOccurs = unbounded.

I was expecting the type "Point" to be created with an argument for "Reason" typed as an Option<Reason[]>. Instead of that the type "Point" requires an array of Reason[] and it's not optional.

here is the part of the .xsd

<xs:complexType name="Point">
    <xs:sequence>
        <xs:element name="Reason" type="Reason" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

the behavior is the same with all the relationships build on minOccurs = 0 and maxOccurs = "unbounded". When minOccurs = 1 or maxOccurs = 1, it works fine.

I hope to be clear enough. If it's not an issue in XmlProvider, can you tell me how I can create a "Point" with no "Reason" ?

Roland

FSharp.Option.Some from C# client side

Description

i have a simple type generated with Xsd type provider,
then a simple record marked CLIMutable i use as interface from c# client side.
in this way i can construct a record from c# and then use it to generate a new XmlElement to serialize.

My problem is that with the option type, referenced from C# side for some fields of the record, which have minOccur = 0, when i pass an option different from None, like FSharpOption.Some(0.00m) i get runtyme type error exceptions from within the serializer.

the error though comes from original Xml type provider:
C:\Git\FSharp.Data\src\Xml\XmlRunti
me.fs:line 219

Repro steps

Please provide the steps required to reproduce the problem

  1. make a library from fsharp side with generated type provider from xsd.
    let the xsd have some optional fields. now make a "bridge" record type (CLIMUtable) from FSHarp so that when you want to create an istance of the provided type, you create an instance of the bridge record type and pass that on to a function, let's say

let makeXml (recordType : RecType) : System.Xml.Linq.XElement
makeXml : RecType -> System.Xml.Linq.XElement

  1. Reference the library from C# app and try to call makeXml, with all option values set to None, you'll notice no exceptions are thrown.

  2. Try to build the recordType instance with at least one optional value set to FSHarpOption.Some(0.00m)

Expected behavior

providing FSharp.Option.Some(T value) to the RecordType constructor should give no errors to,
and i should be able to get a valid System.Xml.Linq.XElement instance as output.

Actual behavior

When i try to build the recordType instance with at least one optional value set to FSHarpOption.Some(value)

Here's the exception i get.

08:19:49,397 [12] Service - System.Exception: Unexpected value: Some(0.00)
   at Microsoft.FSharp.Core.Operators.FailWith[T](String message)
   at Microsoft.FSharp.Core.PrintfImpl.go@523-3[b,c,d](String fmt, Int32 len, FSharpFunc`2 outputChar, FSharpFunc`2 outa, b os, FSharpFunc`2 finalize,
 FSharpList`1 args, Int32 i)
   at Microsoft.FSharp.Core.PrintfImpl.run@521[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args)
   at Microsoft.FSharp.Core.PrintfImpl.capture@540[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args, Type ty, Int32 i)
   at <StartupCode$FSharp-Core>[email protected](T1 inp)
   at <StartupCode$FSharp-Data>.$XmlRuntime.serialize$cont@209(CultureInfo cultureInfo, Object v, Unit unitVar) in C:\Git\FSharp.Data\src\Xml\XmlRunti
me.fs:line 219

Known workarounds

Still have not found a workaround, i'll try to convert options to nullables form fsharp side, yet it's not very comfortable to accomplish in a fast manner.

Related information

  • Windows 8 64 bit
  • master
  • .NET 4.6

Elements with same name but different types are not supported

Description

I am using the library to generate a report based on this schema set :

https://www.esma.europa.eu/sites/default/files/library/2016-_annex_6_firds_reference_data_xml_schema.zip

Specifically, the DRAFT4auth.039.001.01_ESMAUG_DATNWD_1.0.0.xsd schema which has 2 elements with the same name "NonWorkgDay" but different types, one is SecuritiesNonTradingDayReport1, the other is SecuritiesNonTradingDay1.

Repro steps

type Rpt = XmlProvider<Schema = @"DRAFT4auth.039.001.01_ESMAUG_DATNWD_1.0.0.xsd">
Rpt.NonWorkgDay will be defined as self-referencing type instead of referencing the other type.

Expected behavior

Generate 2 distinct types, I guess ?

Actual behavior

Only generates the first type (or at least only one of the types)

Known workarounds

None

Related information

N/A

Monitor memory usage

it seems that a lot of memory is used at design time (at least in Visual Studio 2015) when editing code which uses the type provider with multiple large schemas.
This may be normal and inevitable, but profiling memory usage would be useful.

external schema resolution

The custom xml resolver ResolutionFolderResolver should use the IO facilities of F# Data.
This should allow for embedded resources as well as caching web resources.
Caching may be especially beneficial for common schemas like this

GetSample should not return schema content

Description

Provided type has the GetSample method.
This method returns the content that is passed as static parameter.
If I use Schema parameter then GetSample method returns the schema content.
But schema is not sample.
I think GetSample method should not return schema content.

Repro steps

open FSharp.Data
type T = XmlProvider<Schema = @"path\to\xsd\file">

let f () =
  T.GetSample()  // this returns the content of the schema.

Problem with loading of elements of xml file when schema is build with xsd file

Description

Hi,
I started working with xml files before a short time and was using FSharp.data without FSharp.Data.Xsd and I had no problem, when I tried to pick specific elements form the file.
But the used scheme is quite complex and I hoped to avoid rewriting it completely to a xml file because a xsd file is available.
When I used the FSharp.Data.Xsd everything seemed to work properly because the whole file was loaded as normal but when I tried to pick a specific element the array was always empty or not existing (None).

Repro steps

I thought giving you the code I worked with is sufficient.
Calling the Information of the whole file is no problem but upon calling for specific elements the output is always empty or not existing (None).

#r @"..\packages\FSharp.Data.2.4.6\lib\net45\FSharp.Data.dll"
#r @"..\packages\FSharp.Data.Xsd.1.0.2\lib\net45\FSharp.Data.Xsd.dll"
#r "System.Xml.Linq.dll"

open FSharp.Data

//type SchemeTest = XmlProvider<"..\ExampleFile\Test.txt">
//let sampleTest = SchemeTest.Load("..\ExampleFile\Test.txt")
//sampleTest

type SchemePeptideShaker = XmlProvider<Schema = "..\ExampleFile\MzIdentMLScheme.xsd">
let samplePeptideShaker = SchemePeptideShaker.Load("..\ExampleFile\PeptideShaker_mzid_1_2_example.txt")

samplePeptideShaker

samplePeptideShaker.CvList
|> Array.map (fun cvItem -> cvItem)

Expected behavior

I should give me an array of the different cvItems of the CvList.

Actual behavior

Calling for the cvItems of the CvList results in an empty array.

Known workarounds

When I do not work with the xsd file but with the xml file there is no problem but the example file is incomplete.

Related information

PeptideShaker_Scheme.txt

  • .NET Runtime, CoreCLR or Mono Version
  • Performance information, links to performance testing scripts

Turn the whole project into a PR for FSharp.Data

I really would like some feedback here, especially because reading the recommended guidelines I'm not sure if this project qualifies for having the FSharp namespace.
I opted for a separate project to avoid interfering with a similar attempt; but also because I like the idea of immediately shipping something useful, albeit maybe not tested enough for such a mature and popular library which is FSharp.Data.

Please give an example on how to generate XML having complex XSD

I need to see an example of how to generate XML having this complex XSD (zipped file):

http://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=xLaRDcJryNA=

With that ZIP file contents, today in C# we can use

xsd.exe nfe_v4.00.xsd xmldsig-core-schema_v1.01.xsd /c /edb

Here in Brazil XSD Schemas are being used heavily.

Right now that governament portal indicates 19394 billion documents generated using those XSD schemas.

How to generate XML having those XSD, using F# ?

Schema not parsing

Description

I have this example schema and I would expect it to work, yet it doesnt.

Repro steps

type TestXml = XmlProvider<Schema = """
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
        <xs:complexType name="atest_req">
            <xs:sequence>
                <xs:element ref="data" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
                <xs:attribute name="message" type="xs:string" />
        </xs:complexType>
        <xs:complexType name="btest_res">
            <xs:sequence>
                <xs:element ref="data" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
                <xs:attribute name="message" type="xs:string" />
        </xs:complexType>
        <xs:complexType name="btest_req">
            <xs:sequence>
                <xs:element name="data" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
                <xs:attribute name="message" type="xs:string" />
        </xs:complexType>
        <xs:complexType name="atest_res">
            <xs:sequence>
                <xs:element ref="data" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
                <xs:element name="message" type="xs:string" />
        </xs:complexType>
        <xs:complexType name="data">
            <xs:sequence>
                <xs:element name="trans_no" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="total" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="test_status" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="result" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="trans_type" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="status" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="language" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="error" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="btest" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="reciever" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="printer" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="response" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="window" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element name="maximum " type="xs:string" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
        </xs:complexType>
    </xs:schema>
    """>

Expected behavior

This should parse and generate the type fine.

Actual behavior

Error : The type provider 'ProviderImplementation.XmlProvider' reported an error: The provided sample is neither a file, nor a well-formed XML: The 'http://www.w3.org/2001/XMLSchema:element' element is not supported in this context.

Known workarounds

None

Related information

  • Windows 10
  • Master, 0.0.9
  • .NET Runtime

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.