Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best solution is to remove the <code>&lt;type/&gt;</code> element and only have a <code>xs:choice</code> for <code>&lt;a/&gt;</code> and <code>&lt;b/&gt;</code> and let the application consuming the xml sort out the type. </p> <p>Another solution might be to have a <code>xs:choice</code> for <code>&lt;a/&gt;</code> and <code>&lt;b/&gt;</code> use an xslt script to do a validation of the <code>&lt;type/&gt;</code> element in relation to <code>&lt;a/&gt;</code> and <code>&lt;b/&gt;</code>.</p> <p>First validate the xml against the xmlschema then use the xslt to do a transformation on it, if the result of the transform is empty string it is valid otherwise show the resulting string as an error message.</p> <p>Something like this...</p> <p><em>XmlSchema:</em> </p> <pre><code> &lt;xs:element name="some-element"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="type" type="xs:integer" /&gt; &lt;xs:choice&gt; &lt;xs:element name="a" type="xs:string" /&gt; &lt;xs:element name="b" type="xs:string" /&gt; &lt;/xs:choice&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p><em>Xslt:</em></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:demo="uri:demo:namespace"&gt; &lt;xsl:output method="text" /&gt; &lt;xsl:template match="/demo:some-element"&gt; &lt;xsl:if test="type = 1 and not(demo:a)"&gt; When type equals 1 element a is requred. &lt;/xsl:if&gt; &lt;xsl:if test="type = 2 and not(demo:b)"&gt; When type equals 2 element b is requred. &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    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.
    2. 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