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

Schema with restriction and base="xsd:dateTime" #114

Closed
oskar-r opened this issue Jul 22, 2020 · 1 comment
Closed

Schema with restriction and base="xsd:dateTime" #114

oskar-r opened this issue Jul 22, 2020 · 1 comment

Comments

@oskar-r
Copy link

oskar-r commented Jul 22, 2020

Came across the following when trying to use xsdgen with a xsd-schema containing

  <xsd:simpleType name="nonEmptyDate"> 
        <xsd:restriction base="xsd:dateTime"> 
            <xsd:minExclusive value="2000-01-01T00:00:00Z"/>
            <xsd:maxExclusive value="2100-01-01T00:00:00Z"/>
        </xsd:restriction> 
    </xsd:simpleType>  

Resulted in following error.

Error at simpleType(nonEmptyDate)>restriction: strconv.ParseFloat: parsing "2000-01-01T00:00:00Z": invalid syntax

I managed to get it to parse by adding and additional else if clause which checks for DateTime in

parseSimpleRestriction() 
...
else if v, ok := base.(Builtin); ok && v == DateTime {
    d, err := time.Parse(time.RFC3339, el.Attr("", "value"))
    if err != nil {
        stop(err.Error())
    }
    r.MinDate = d
}

This seems more than a walk around than a patch though.

@droyo
Copy link
Owner

droyo commented Jul 24, 2020

This seems like a perfectly valid fix; we're already special-casing Date builtins in a similar way. It's a little unfortunate that it needs to be copied twice to check for min and max, but it's not the end of the world.

There are probably a few other base types where min/max are still valid restrictions but which don't make sense as floating-point numbers. But I'm happy to accept a PR just handling DateTime in the way you've done.

Thanks!

oskar-r pushed a commit to oskar-r/go-xml that referenced this issue Jul 24, 2020
DateTime as valid type when parsing with simple restriction.
droyo added a commit that referenced this issue Jul 24, 2020
@droyo droyo closed this as completed Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants