-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support XSD in XmlProvider #57
Comments
+1 This seems to be a more robust option than guessing types from a sample. |
+1 I could really use this. |
Creating the types is easy once you inferred the schema. The problem here is we need something that can understand XSD files - and works on mono. I think xsd.exe (http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.80).aspx) is probably not the way to go. |
👍 Thanks, @tpetricek. I looked for this but couldn't find it. |
It would be great to have this feature - I think this is something that can be done without messing too much with the details of the XML type provider, so it is a perfect project for a new contributor :-). I'm happy to help anyone who is interested in looking into this (@panesofglass ;-)). The easiest way to support this would be to parse the XSD file and build a value of The XML provider does not support all #r "System.Xml.Linq.dll"
#r @"C:\Tomas\Projects\FSharp.Data\bin\FSharp.Data.DesignTime.dll"
open System.Xml.Linq
open ProviderImplementation
open FSharp.Data.RuntimeImplementation.StructuralTypes
fsi.AddPrinter(fun (t:System.Type) -> t.Name)
let doc = XDocument.Parse("""<root>
<attrs id="1" />
<text>hello</text>
<tricky>3.14</tricky>
<tricky>true</tricky>
</root>""")
let culture = System.Globalization.CultureInfo.InvariantCulture
XmlInference.inferType culture false doc.Root For the example, you get: Record // An XML element is always represented as Record
(Some "root", // This is the name of the record
[{Name = ""; // A list of attributes/children - the name "" is
Optional = false; // special and means the body of the element
Type = // (optional means it may/may not be there)
Collection // Collection represents multiple children
(map
[(Record (Some "attrs"), // This is InferedTypeTag - it should be
(Single, // basically the name of the element
Record (Some "attrs",[{Name = "id"; // Attribute 'id' of type 'int'
Optional = false; // .. that's not optional
Type = Primitive (Int32,null);}])));
(Record (Some "text"),
(Single, // Single vs. Multiple - how many times
// can the child element appear?
Record (Some "text",[{Name = ""; // Body is non-optional
Optional = false; // .. string
Type = Primitive (String,null);}])));
(Record (Some "tricky"),
(Multiple,
Record
(Some "tricky",
[{Name = "";
Optional = false;
Type = // This represents type that is a choice
Heterogeneous // between multiple possible options -
(map // here number of boolean
[(Number, Primitive (Decimal,null));
(Boolean, Primitive (Boolean,null))]);}])))]);}])``` |
This may be a good opportunity to finally learn how type providers work. I'm interested. That said, you can look around and see just how quick I am to finish things. :) Are you thinking a custom XSD parser? What are the limitations of using other, external libraries? I forget. |
If there are some external libraries that we can easily rely on, that's probably fine - I'm not sure how difficult would it be to just read XSD as a XML document and work with that... I'll be certainly happy to help (and maybe I'll recruit more people :-)) but I'm probably not able to lead the effort. |
I'm not sure reading Xsd's as plain Xml documents is a good way forward. Xsd's are complicated beasts. I started experimenting with this using classes in System.Xml.Schema but I never really got anywhere. Lack of time/ran out of energy.. You should probably get some tricky Xsd's to try out with the TP to understand why it's not trivial. Often, you'll get some complex Xsd from a third party and it would be awesome to have a robust Xsd TP for them. |
.NET already have build in support for parsing XSD - XmlSchema. Main problem is to convert XmlSchema model into appropriate for typeprovider model. So for example logic that says that "xsd:element with xsd:sequence of xsd:element should result as DTO" is hardcoded in xsd.exe tool. This logic is internal and so need to be reimplemented. XmlSchemaElement already have some information like IsAbstract that could help. |
Cool - I did not know about |
Maybe following codeplex project could help : |
@runefs, seems you're working on a XSD type provider (http://stackoverflow.com/questions/20466880/getting-compile-error-on-provided-type). Would you like to integrate it in FSharp.Data? |
I might be able to contribute. i'm currently working on a XSD type provider. It's currently based on System.Xml.Linq but 'd look into changing that to System.Xml.Schema |
Transformations would be so nice. I mentioned XQuery to @mausch in the issues for his XmlLiteralsTypeProvider. XSLT would also be interesting, but I though XQuery might be a little simpler to implement in F#. |
I'm quite new to type providers (so maybe I'm totally wrong with my question) but could such an XSD provider be used instead of providing a sample XML to the XML type provider? |
@pver that's the idea, instead of giving an xml example, provide a xsd that defines the structure of the xml, but still generate types for the xml described by the xsd, not for the xsd itself |
@ovatsus thanks for the confirmation, that sounds great :) |
I've had lots of people ask me too |
I made progress and then did nothing about it. Being Willy and not Mvh Den 19/03/2014 kl. 19.42 skrev Gustavo Guerra notifications@github.com: @runefs https://github.com/runefs, @rojepp Reply to this email directly or view it on |
Ok ok I'll get to it :) if nothing else I have a very working prototype I Mvh Den 19/03/2014 kl. 20.53 skrev Don Syme notifications@github.com: I've had lots of people ask me too Reply to this email directly or view it on |
Great! Let me know if you need help merging, there's been quite a few internal changes to FSharp.Data in the meantime. Was the existing InferedType data model enough or did you have to extend it? |
If you need help with testing I have some rather complicated data with schema (XSD files) that I could throw at it. |
I'm gonna need some help on this one And John please send me the XSDs (preferably with sample XML as well) Br 2014-03-19 22:15 GMT+01:00 John Tarbox notifications@github.com:
|
There are several kinds of tests:
A bit of this is on http://fsharp.github.io/FSharp.Data/contributing.html, but not much. It would be great if you could improve it based on your experience. Let me know if you need more help. You can also push to your repo and I can have a look if you want |
Just to add to this - I don't think it matters if your XSD provider does not work perfectly (or at all) with John's complex schema(s). What's important is a base we can work from that covers the very fundamental blocks of XSD, and we can then work on it together from there. |
no problem |
So I got the code working with compiled schema sets and also with what I 2015-08-11 15:56 GMT+02:00 Gustavo Guerra notifications@github.com:
|
Glad to see @runefs progress, so I better quit experimenting on my own. |
@giacomociti I don't think it as such is caused by the build. It seems to 2015-08-27 22:02 GMT+02:00 Giacomo Citi notifications@github.com:
|
Hi, I'm working on a project at the moment that requires us to produce an XML document based on quite a strict and large schema and I instantly thought "F# type providers!". Did you manage to get this working at all? |
Currently there's a cross compilation bug. System.Xml behaves differently 2015-09-08 17:50 GMT+02:00 Clint Pearson notifications@github.com:
|
I see, is there a place I can grab it for targeting MS .NET? I'll only be running on Windows anyway. |
@ckpearson this seems to be the place to grab it: https://github.com/fsharp/FSharp.Data/tree/XsdProvider I'm looking forward to this too, now I'm trying to come up with XML examples to feed the TP to cover all properties I need to write out other XML, would be nicer to define it in xsd |
@giacomociti thanks for the advice! |
I've spent some time on the XsdProvider again however after fetching the 2015-12-03 9:47 GMT+01:00 Giacomo Citi notifications@github.com:
|
I'm currently stuck with this error message "....FSharp.Data.Tests/JsonProvider.fs(22,22): Error FS1109: A reference to Since I haven't changed anything (willingly at least) with regards to the 2015-12-09 19:42 GMT+01:00 rune funch søltoft rune@funch.dk:
|
👍 |
I've been playing again with my implementation and released it as a separate project. I just referenced most source code of Of course I just could have made a PR to So I'm glad if someone is willing to experiment with |
I have a complex XSD Schema (multiple files). How can I use F# to read it so I can use this to generate an output XML, with my data on that XSD structure? nfe_v4.00.xsd and xmldsig-core-schema_v1.01.xsd http://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=BALgvpK9Jvo= In C# I could do xsd.exe nfe_v4.00.xsd xmldsig-core-schema_v1.01.xsd /c /edb How can I do this in F# (Code Generated F# Types), or, can I read these two XSD directly on F# (F# Type Provider) |
hi @TonyHenrique, xsd is not supported yet in F# Data. The XsdProvider branch is not merged, nor is my PR #1004 |
I'll have a look at trying to merge that this month. Should I consider that PR as a replacement for the old branch? |
Yes, the PR is an alternative to the existing branch |
@giacomociti After adding ResolutionFolder, it can read the XML using the 2 XSD definitions. |
@TonyHenrique type providers are more geared towards reading, but writing is supported simply using the constructors on the types generated by the XmlProvider, as explained in the Transforming XML section towards the end of the XmlProvider documentation |
Has this been resolved? |
I'm already using the separate FSharp.Data.Xsd Type Provider, but it would be awesome if the excellent work of @giacomociti could be merged into FSharp.Data. |
No description provided.
The text was updated successfully, but these errors were encountered: