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

XSD for constraints *and* default value #6

Open
briesenberg07 opened this issue Jul 3, 2021 · 5 comments
Open

XSD for constraints *and* default value #6

briesenberg07 opened this issue Jul 3, 2021 · 5 comments
Assignees
Labels
MESSY ISSUE xsd to do with schemas for prop_set instances, get_prop_set instance, etc.

Comments

@briesenberg07
Copy link
Contributor

...to support use of CTRL + SPACE in oXygen

@briesenberg07 briesenberg07 self-assigned this Jul 3, 2021
@briesenberg07
Copy link
Contributor Author

Seems to work just fine:

See...

    <xs:simpleType name="localid_attr">
        <xs:restriction base="xs:string">
            <xs:pattern value="\S+"/>
            <xs:enumeration value="!NEED_LOCAL_ID!"/>
        </xs:restriction>
    </xs:simpleType>

...and

    <xs:simpleType name="form_order_type">
        <xs:restriction base="xs:decimal">
            <xs:minInclusive value="0.0"/>
            <xs:maxInclusive value="1.0"/>
            <xs:enumeration value="0.5"/>
        </xs:restriction>
    </xs:simpleType>

@briesenberg07
Copy link
Contributor Author

briesenberg07 commented Jul 7, 2021

It seems I was wrong with regard to the mixing of different xs:restriction elements, or at least with regard to the mixing of xs:pattern and xs:enumeration above:

image

Same goes for minInclusive + maxInclusive + enumeration--seems only enumeration is taken into account during validation:

image

@briesenberg07 briesenberg07 reopened this Jul 7, 2021
@briesenberg07
Copy link
Contributor Author

briesenberg07 commented Jul 8, 2021

I'd like to do for form_order element values

@gerontakos
Copy link
Collaborator

Here are some jumbled thoughts, I hope they help.

I'm not entirely sure what you want to do. However, as regarding defaults, as I remember it you declare those as part of the element or attribute declaration, not as part of the type.

<xs:attribute name="fake" type="mapid_propSet_attr" **default="enter_rda_entity_here"**>

So you have to repeat the default for every element or attribute that share a common type (when they do in fact have a common default).

Default values in XML Schema have always been a mystery to me. I think it's useful for content completion when authoring an XML document based on the schema, or when deriving an XML document from an XML schema. However I haven't used it otherwise. I thought an XML Schema processor was supposed to insert a default value in the XML document when there is no value present and a default is specified; I have never seen that happen.

The problem you present is not just about default values but, rather, an exploration of simple type definitions; in particular, simple type restrictions; and even more particular, combining facets in a restriction.

In both your examples, say example 2:

<xs:simpleType name="form_order_type">
    <xs:restriction base="xs:decimal">
        <xs:minInclusive value="0.0"/>
        <xs:maxInclusive value="1.0"/>
        <xs:enumeration value="0.5"/>
    </xs:restriction>
</xs:simpleType>

...you're using xs:enumeration in an odd way. xs:enumeration in this case is used to create a set of valid values
for a simple type restriction. You created a set with one item: (0.5). This means the only valid value is 0.5. Anything else would not be valid, even if it falls between the specified minExclusive and maxInclusive, right?

I believe when minInclusive, maxInclusive and enumeration are all used together, the XML instance needs to meet all the facets specified. If the facets contradict each other, you will never be able to validate. The XML Schema document however should validate with the contradiction. I'm not totally sure about that: there are many potential areas of conflict when there's, say, a default, a base type, and multiple restriction facets. I'm not sure how these will be handled by your processor, you'll have to explore.

The xs:pattern facet also creates a set of valid values that conform to a specified regular expression. It works very much like xs:enumeration. In both cases I believe only one of the members of the set need to be matched in the XML instance.

Okay let's see where that leaves you.

I'm not sure about preventing duplicate values for a specific element or attribute, I've never done that, but I could check into it if that's part of this issue also.

@briesenberg07 briesenberg07 changed the title Possible to provide value constraints *and* a default value using XSD? XSD for constraints *and* default value for *text nodes* Aug 13, 2021
@briesenberg07 briesenberg07 changed the title XSD for constraints *and* default value for *text nodes* XSD for constraints *and* default value Aug 13, 2021
@briesenberg07 briesenberg07 added the xsd to do with schemas for prop_set instances, get_prop_set instance, etc. label Nov 8, 2021
@briesenberg07 briesenberg07 removed their assignment Aug 13, 2022
@briesenberg07 briesenberg07 self-assigned this Mar 8, 2023
@briesenberg07
Copy link
Contributor Author

Possible to assign default @xml:lang="en" for lang_string_type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MESSY ISSUE xsd to do with schemas for prop_set instances, get_prop_set instance, etc.
Projects
None yet
Development

No branches or pull requests

2 participants