FSharp.Data
FSharp.Data copied to clipboard
XmlProvider does not parse DateTimeOffset values in format "YYYY-MM-DDThh:mm:ss"
This problem is related to FSharp.Data version 3.3.3.
I am trying to create XmlProvider from XSD but it fails on parsing xs:dateTime
values. When trying to access the property, I am getting an error System.Exception: Expecting DateTimeOffset in Value, got 2020-01-20T12:15:00
The same problem happens when accessing XML Values and when accessing XML Attributes.
See the minimal example below.
Is there some workaround or setting that I am missing or is this a bug?
thank you.
open FSharp.Data
[<Literal>]
let xsd =
"""
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="start" type="xs:dateTime" />
</xs:schema>
"""
type Person = XmlProvider<Schema = """
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="surname" type="xs:string"/>
<xs:element name="birthDate" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>""">
[<EntryPoint>]
let main argv =
let p =
Person.Parse(
"""
<person>
<surname>Stastny</surname>
<birthDate>2020-01-20T12:15:00</birthDate>
</person>
""")
printfn "%A" p.BirthDate
0
I'm afraid it's a bug because the XML is valid. An ugly workaround is to avoid accessing the BirthDate property and use the untyped XElement property instead to read the element value
@giacomociti thank you for your answer, I was afraid of that. I am using exactly the same workaround as you have described, so it at least does not block. I will keep it in the code until this issue gets resolved.
this commit may fix the issue, but I haven't submitted a PR yet because it is a breaking change for the other type providers (notice I had to change a test of CSV provider).
The problem is that the parsing functions are shared by all type providers.
Thank you for a quick fix! I am on different project at the moment, I will try the fix next week.
@giacomociti that does it for me, thank you