Skip to content

String-derived element is marked as optional when minLength > 0 #19

@antonielly

Description

@antonielly

The generator available at
https://xsd-forms.herokuapp.com/
appears to look at the "pattern" but ignore "minLength" or "length" in order to decide marking a string field as mandatory (*) or optional ().

Minimal working examples:

a) The defect appears

<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:this="http://example.com/"
    targetNamespace="http://example.com/"
    xmlns="http://www.w3.org/2001/XMLSchema">

    <simpleType name="NonEmptyString">
        <restriction base="string">
            <minLength value="1"/>
        </restriction>
    </simpleType>

    <element name="nonEmptyString" type="this:NonEmptyString"/>
</schema>

b) The defect appears

<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:this="http://example.com/"
    targetNamespace="http://example.com/"
    xmlns="http://www.w3.org/2001/XMLSchema">

    <simpleType name="NonEmptyString">
        <restriction base="string">
            <pattern value="[0-9A-Z]*"/>
            <minLength value="1"/>
        </restriction>
    </simpleType>

    <element name="nonEmptyString" type="this:NonEmptyString"/>
</schema>

c) The defect does not appear (i.e. it works correctly, as it should)

<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:this="http://example.com/"
    targetNamespace="http://example.com/"
    xmlns="http://www.w3.org/2001/XMLSchema">

    <simpleType name="NonEmptyString">
        <restriction base="string">
            <pattern value="[0-9A-Z]+"/>
        </restriction>
    </simpleType>

    <element name="nonEmptyString" type="this:NonEmptyString"/>
</schema>

d) The defect appears

<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:this="http://example.com/"
    targetNamespace="http://example.com/"
    xmlns="http://www.w3.org/2001/XMLSchema">

    <simpleType name="SingleCharacter">
        <restriction base="string">
            <length value="1"/>
        </restriction>
    </simpleType>

    <element name="singleCharacter" type="this:SingleCharacter"/>
</schema>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions