nexusformat / definitions

Definitions of the NeXus Standard File Structure and Contents
https://manual.nexusformat.org/
Other
26 stars 55 forks source link

Allowing choice for fields #1357

Open domna opened 4 months ago

domna commented 4 months ago

NXDL supports a choice for groups (https://manual.nexusformat.org/defs_intro.html#choice). I think it would be useful to also allow the choice to select between multiple fields. It could then be an unnamed choice tag.

Here is an example of my idea:

 <choice>
      <field name="option1">
        <doc>
          A field which is required if option2 is not supplied.
          If option2 is supplied, option1 cannot be supplied anymore (exclusive or relationship)
        </doc>
      </field>
      <field name="option2">
        <doc>
          A field which is required if option1 is not supplied.
          If option1 is supplied, option2 cannot be supplied anymore (exclusive or relationship)
        </doc>
      </field>
</choice>

It could then also be properly distinguished: a choice tag without a name could only contain fields and a choice tag with a name could only contain groups.

prjemian commented 4 months ago

Show us the XML Schema code (for the nxdl.xsd file) that implements the choice element. The NXcansas definition has such a situation, involving the definition of the slit length.

domna commented 4 months ago

I'm not really experienced in writing xsd but I tried to draft something:

    <xs:element name="choice">
        <xs:complexType>
            <xs:choice>
                <xs:sequence>
                  <xs:element name="group" type="nx:groupType" minOccurs="2" maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:sequence>
                  <xs:element name="field" type="nx:fieldType" minOccurs="2" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:choice>
        </xs:complexType>
    </xs:element>

as far as I understood it is not really possible to disallow the use of the name attribute. There might be the possibility to use assert for XSD1.1, but I'm not sure whether this version works with the current nxdl.xsd so I left it out.