Skip to content

Union of different types (including empty string) #13

@csoete

Description

@csoete

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions