Skip to content
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

XmlProvider does not parse DateTimeOffset values in format "YYYY-MM-DDThh:mm:ss" #1301

Open
kstastny opened this issue Jan 20, 2020 · 5 comments
Open

Comments

@kstastny
Copy link

@kstastny kstastny commented Jan 20, 2020

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
@giacomociti
Copy link
Contributor

@giacomociti giacomociti commented Jan 21, 2020

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

@kstastny
Copy link
Author

@kstastny kstastny commented Jan 22, 2020

@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.

@giacomociti
Copy link
Contributor

@giacomociti giacomociti commented Jan 24, 2020

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.

@kstastny
Copy link
Author

@kstastny kstastny commented Jan 27, 2020

Thank you for a quick fix! I am on different project at the moment, I will try the fix next week.

@kstastny
Copy link
Author

@kstastny kstastny commented Feb 3, 2020

@giacomociti that does it for me, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.