fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
816 stars 288 forks source link

Xsd Choice is interpreted as Option<> * Option<_>..... #1452

Open MarkNicholls opened 2 years ago

MarkNicholls commented 2 years ago

This has been noted many years ago with JSON, I assume that does the same thing.

type RawXml3 = XmlProvider<Schema = """
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="rootType">
        <xs:sequence>
            <xs:element name="vehicle">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="CAR"/>
                        <xs:element name="BICYCLE"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="ROOT" type="rootType">
    </xs:element>
</xs:schema>""">

let t = RawXml3.Parse "file.xml"

match t.Vehicle.Bicycle, t.Vehicle.Car with
| Some bike, None -> 
    printfn "a bike"
| None, Some car -> 
    printfn "a car"
| None, None -> 
    printfn "not allowed"
| Some _ , Some _ -> 
    printfn "not allowed"

Not the end of the world, but not ideal, we have a state space that allows None None and Some _ Some _, both of which are illegal.

is there some way to turn on choice?

(The situation with multiple choices values is I think slightly worse because it maps to Car[] and Bicycle[], rather than Choice<Car,Bicycle>[], so I assume it destroys the relative ordering of Cars and Bicycles e.g.

<Car/>
<Bicycle/>
<Car/>

and

<Car/>
<Car/>
<Bicycle/>

will be indistinguishable, rarely an issue, but some XML is order sensitive)