FIXTradingCommunity / fix-simple-binary-encoding

A FIX standard for binary message encoding
Other
253 stars 67 forks source link

Possible inconsistent usage of unqualified locals in XSD? #117

Closed alexeq closed 1 year ago

alexeq commented 4 years ago

All XML schemas for SBE set attribute elementFormDefault="unqualified" which specifies that all local elements and attributes are unqualified (see https://www.w3.org/TR/xmlschema-0/#NS). But unfortunately those schemas do define element message globally (not inside the messageSchema definition). This leads to somewhat confusing SBE XML:

<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" ...>
    <types> <!-- no namespace here! -->
        <type ...> <!-- no namespace here! -->
    <types>
    <sbe:message ...> <!-- namespace required here! -->
        <field ...> <!-- no namespace here! -->
    </sbe:message>
</sbe:messageSchema>

where all elements and attributes inside messageSchema do not use namespace prefix with single exception of message element that requires it in order to make a valid XML file.

Is this intended behavior? If not it is relatively easy to fix by moving the definition of the message element inside messageSchema definition (just below types definition in the xs:sequence). This would allow us to write SBE XML as:

<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" ...>
    <types>
        <type ...>
    <types>
    <message ...> <!-- consistent with other elements -->
        <field ...>
    </message>
</sbe:messageSchema>

Better yet, I would propose to use qualified locals (elementFormDefault="qualified") as suggested by some XSD best practice guides. This would allow us to write SBE XML using default namespace:

<messageSchema xmlns="http://fixprotocol.io/2016/sbe" ...>
    <types>
        <type ...>
    <types>
    <message ...>
        <field ...>
    </message>
</messageSchema>

For backward compatibility (old SBE XML files) adding default namespace would allow mixed content inside XML:

<messageSchema xmlns="http://fixprotocol.io/2016/sbe" xmlns:sbe="http://fixprotocol.io/2016/sbe"...>
    <!-- both 'message' and 'sbe:message' elements are allowed -->
</messageSchema>
donmendelson commented 4 years ago

I'm inclined to agree, and other FIX XML schemas have elementFormDefault="qualified". I don't recall why this one is different--it's been this way since at least version 1.0 RC3.

alexeq commented 4 years ago

Using "qualifed" elements would allow to validate XML (and have IDE auto-completion) for partial types and messages definitions.