fix-simple-binary-encoding icon indicating copy to clipboard operation
fix-simple-binary-encoding copied to clipboard

Possible inconsistent usage of unqualified locals in XSD?

Open alexeq opened this issue 5 years ago • 2 comments

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>

alexeq avatar Apr 23 '20 20:04 alexeq

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.

donmendelson avatar Apr 27 '20 15:04 donmendelson

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

alexeq avatar Apr 28 '20 10:04 alexeq