Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your constraints are not entirely clear, so a number of schemas would validate the XML depending on how loose/tight you would want the validation to be. This example shows a schema that mandates exactly two elements inside the element and they must have a "name" attribute with the values "status" or "message". </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="root"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="str" type="StrType" minOccurs="2" maxOccurs="2"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="StrType"&gt; &lt;xs:simpleContent&gt; &lt;xs:extension base="xs:string"&gt; &lt;xs:attribute name="name" type="StrAttribute" use="required" /&gt; &lt;/xs:extension&gt; &lt;/xs:simpleContent&gt; &lt;/xs:complexType&gt; &lt;xs:simpleType name="StrAttribute"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:enumeration value="status"/&gt; &lt;xs:enumeration value="message"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:schema&gt; </code></pre> <p>Of course, this would allow two elements both with the name attribute set to "message", or with "message" first, then status. I believe the schema cannot define a sequence containing two elements of the same name but different types which you would need if you required the validation to ensure that the first always contained "status" and the second one contained "message".</p>
 

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