Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you wish that you could write Schema like this:</p> <pre><code>&lt;!-- WARNING: this is not valid Schema --&gt; &lt;xs:complexType name="composite-key"&gt; &lt;xs:choice maxOccurs="unbounded"&gt; &lt;xs:element name="key" type="simple-key"/&gt; &lt;xs:element name="key" type="composite-key"/&gt; &lt;/xs:choice&gt; &lt;xs:attribute name="name" type="xs:string" use="required"/&gt; &lt;/xs:complexType&gt; </code></pre> <p><em>simple-key</em> would be defined elsewhere. This is not valid Schema since you are not allowed to use the same element name twice. If Schema supported this, it would have a devil of a time disambiguating element types based upon their structure alone.</p> <p>If you have control over the XML, you can make this work by changing one or both of the element names. For example, one might use <em>val</em> for simple values and <em>obj</em> for composite ones:</p> <pre><code>&lt;xs:complexType name="composite-key"&gt; &lt;xs:choice maxOccurs="unbounded"&gt; &lt;xs:element name="val" type="simple-key"/&gt; &lt;xs:element name="obj" type="composite-key"/&gt; &lt;/xs:choice&gt; &lt;xs:attribute name="name" type="xs:string" use="required"/&gt; &lt;/xs:complexType&gt; </code></pre> <p>Adjust the names to taste. This would be my recommended solution as it emphasizes clarity. However, the element names may be out of your control. If so, a less satisfactory solution would be as follows:</p> <pre><code>&lt;xs:complexType name="key" mixed="true"&gt; &lt;xs:sequence maxOccurs="unbounded"&gt; &lt;xs:element name="key" type="key"/&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="name" type="xs:string" use="required"/&gt; &lt;xs:attribute name="type" type="xs:string"/&gt; &lt;xs:attribute name="representation" type="xs:string"/&gt; &lt;/xs:complexType&gt; </code></pre> <p>The key differences here are the <em>mixed</em> content type, and the unfortunate fact that the declaration is now an amalgam of the simple and composite key types. I say that this is "less satisfactory" because now you must perform additional validity checking in your own code, after Schema has finished with it. For example, you would need to validate whether the set of attributes given make sense for the implied key type. Also, the example as written would permit text to appear anywhere between nested key elements -- probably something you do not want.</p> <p>[edit: the same question is discussed on stackoverflow <a href="https://stackoverflow.com/questions/2468843/how-define-several-elements-with-same-name-but-different-type-in-xsdchoice-elem/2494088#2494088">here</a>]</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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