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

Union of different types (including empty string) #13

Open
csoete opened this issue Nov 9, 2016 · 1 comment
Open

Union of different types (including empty string) #13

csoete opened this issue Nov 9, 2016 · 1 comment

Comments

@csoete
Copy link

csoete commented Nov 9, 2016

I have the following xsd schema which fails.

  <xsd:simpleType name="emptyType" >
    <xsd:restriction base="xsd:string">
      <xsd:length value="0" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="empty-or-decimal">
    <xsd:union memberTypes="xsd:decimal emptyType" />
  </xsd:simpleType>
  <xsd:simpleType name="empty-or-integer">
    <xsd:union memberTypes="xsd:integer emptyType" />
  </xsd:simpleType>

Expected result would probably be:

<dataset value=''/> -> {'value': ''}
<dataset value='1'/> -> {'value': 1}

To get it working at all I changed validator.js (line 387) from:
else if (value.value) {
to:
else if (value.value !== undefined && value.value !== null) {

Another issue had something to do with namespacing which I don't really understand. Somehow my own type caused an assertion. To get around that I added (to the namespacedName function in the xsd.js file):

  else if (self.targetNamespace) {
    return '{' + self.targetNamespace + '}' + name;
  }

If you could give me some feedback I would love to turn it into a pull request.

@csoete
Copy link
Author

csoete commented Nov 9, 2016

Maybe it would be nice to register custom parser for custom types.

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

1 participant