Note that there are some explanatory texts on larger screens.

plurals
  1. POSame element name in xsd, but different validation logic
    text
    copied!<p>I have xml file that seems like that</p> <pre><code>&lt;doc&gt; &lt;field name="simple_meta"&gt;book&lt;/field&gt; &lt;field name="complex_meta"&gt;journal&lt;/field&gt; &lt;field name="text_date"&gt;some text&lt;/field&gt; &lt;/doc&gt; </code></pre> <p>I would like to validate element text by pattern based on value in attribute "name". that is, if the value of attribute is "simple_meta" I want to make the "simpleRestriction" validation, in case of the "complex_meta" to make the "complexRestriction" validation. The problem is that I cannot define element with same name under the same node. Can someone to help me to resolve this problem?</p> <pre><code>&lt;xs:schema ......&gt; &lt;xs:simpleType name="simpleRestriction"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:maxLength value="20"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:simpleType name="complexRestriction"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:maxLength value="10"/&gt; &lt;xs:pattern value="([\w])*"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:element name="str"&gt; &lt;xs:complexType&gt; &lt;xs:simpleContent&gt; &lt;xs:extention base="simpleRestriction"&gt; &lt;xs:attribute name="name"&gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:pattern value="simple_meta"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:attribute&gt; &lt;/xs:extention&gt; &lt;/xs:simpleContent&gt; &lt;/xs:ComplexType&gt; &lt;/xs:element&gt; &lt;xs:element name="str"&gt; &lt;xs:complexType&gt; &lt;xs:simpleContent&gt; &lt;xs:extention base="complexRestriction"&gt; &lt;xs:attribute name="name"&gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:pattern value="complex_meta"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:attribute&gt; &lt;/xs:extention&gt; &lt;/xs:simpleContent&gt; &lt;/xs:ComplexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre>
 

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