Note that there are some explanatory texts on larger screens.

plurals
  1. POXSD Complex Enumeration
    primarykey
    data
    text
    <p>This is my first question on stackoverflow (I have usually been able to figure out my problems with the answers already here).</p> <p>This is similar to these questions, but I think my question is a little different (also, XSD is really hard):</p> <ul> <li><a href="https://stackoverflow.com/questions/2265978">XSD: How to restrict enumeration values of a derived complex type?</a></li> <li><a href="https://stackoverflow.com/questions/2540752">Enumeration of a complex type</a></li> </ul> <p>I am trying to define a restricted set of "types" that represent parameter data types. E.g.</p> <pre><code> - Binary bit-mapped B/BM 1 byte - Unsigned Integer U/I 2 bytes - Alphanumeric ALPHA 1 byte - etc... </code></pre> <p>So I have come up with the following xsd:</p> <pre><code>&lt;xs:complexType name="parameterDataType" abstract="true"&gt; &lt;xs:sequence&gt; &lt;xs:element name="type" type="xs:string" /&gt; &lt;xs:element name="abbreviation" type="xs:string" /&gt; &lt;xs:element name="length" type="xs:positiveInteger" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="binaryBitMappedType"&gt; &lt;xs:complexContent&gt; &lt;xs:restriction base="parameterDataType"&gt; &lt;xs:sequence&gt; &lt;xs:element name="type" type="xs:string" fixed="Binary Bit-Mapped" /&gt; &lt;xs:element name="abbreviation" type="xs:string" fixed="B/BM" /&gt; &lt;xs:element name="length" type="xs:positiveInteger" fixed="1" /&gt; &lt;/xs:sequence&gt; &lt;/xs:restriction&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; etc... </code></pre> <p>NOTE WELL: I also tried this with a sequence and "type, abbreviation, length" being xs:attributes, so if that's a better solution let me know.</p> <p>This works fine but it requires the XML to redefine the element as their restricted values (otherwise it is not valid), a bit like so:</p> <pre><code>&lt;message&gt; &lt;id&gt;123&lt;/id&gt; &lt;name&gt;Some status type message&lt;/name&gt; &lt;dataType xsi:type="binaryBitMappedType"&gt; &lt;type&gt;Binary Bit-Mapped&lt;/type&gt; &lt;abbreviation&gt;B/BM&lt;/abbreviation&gt; &lt;length&gt;1&lt;/length&gt; &lt;/dataType&gt; ...etc &lt;/message&gt; &lt;message&gt; &lt;id&gt;321&lt;/id&gt; &lt;name&gt;A DIFFERENT status type message&lt;/name&gt; &lt;dataType xsi:type="binaryBitMappedType"&gt; &lt;type&gt;Binary Bit-Mapped&lt;/type&gt; &lt;abbreviation&gt;B/BM&lt;/abbreviation&gt; &lt;length&gt;1&lt;/length&gt; &lt;/dataType&gt; ...etc &lt;/message&gt; &lt;message&gt; &lt;id&gt;456&lt;/id&gt; &lt;name&gt;a continuous value type message&lt;/name&gt; &lt;dataType xsi:type="unsignedIntegerType"&gt; &lt;type&gt;Unsigned Integer&lt;/type&gt; &lt;abbreviation&gt;U/I&lt;/abbreviation&gt; &lt;length&gt;2&lt;/length&gt; &lt;/dataType&gt; ...etc &lt;/message&gt; </code></pre> <p>Is there a way to avoid having to redefine these values in the XML (can the definition be pulled in from the XSD, or assumed from the XSD?) Alternatively, can the definitions be provided in their own XML file and then those be "imported" in based on the xsi:type?</p> <p>Something a little more like this?</p> <pre><code>&lt;message&gt; &lt;id&gt;123&lt;/id&gt; &lt;name&gt;Some status type message&lt;/name&gt; &lt;dataType xsi:type="binaryBitMappedType" /&gt; &lt;!-- don't have to repeat the dataType contents --&gt; ...etc &lt;/message&gt; &lt;message&gt; &lt;id&gt;321&lt;/id&gt; &lt;name&gt;A DIFFERENT status type message&lt;/name&gt; &lt;dataType xsi:type="binaryBitMappedType" /&gt; &lt;!-- don't have to repeat the dataType contents --&gt; ...etc &lt;/message&gt; </code></pre> <p>Or am I on a hiding to nothing? Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload