I’m writing an XML schema for the first time and I found some usefull tools to help me writing it.
Now I’m in a strange situation. The schema I wrote is valid for some tools and not for some others.
This schema is a mix of "all", "sequence" and "group". Here is my XML schema:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:group name="test">
<xsd:all>
<xsd:element name="e2" minOccurs="0" maxOccurs="1"/>
<xsd:element name="e3" minOccurs="0" maxOccurs="1"/>
<xsd:element name="e4" minOccurs="0" maxOccurs="1"/>
</xsd:all>
</xsd:group>
<xsd:element name="e0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="e1" maxOccurs="unbounded"/>
<xsd:group ref="test"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Is this schema right?
It goes right with this validator and this one too but the XML Tools plugin for Notepad++ says "Unable to parse schema file".
P.S: I wrote this schema because I wanted to have an element "e0" with this the possibility to have a mix of e1, e2, e3 and e4. e2, e3 and e4 should appear 0 or 1 time and e1 could occurs an illimited times.
For example this XML files should pass:
<e0>
<e1/>
<e1/>
<e1/>
<e1/>
<e1/>
<e2/>
</e0>
<e0>
<e2/>
<e3/>
<e4/>
</e0>
<e0>
<e1/>
<e2/>
<e3/>
<e4/>
</e0>
Do you know an other way to do this?
Thanks
The schema you have seems to be invalid according to the 1.0 version which states plainly here (Primer) that
XML Schema stipulates that an all group must appear as the sole child at the top of a content model.Alternatively, try to read section 3.8.6 of the XML Schema Structures here. To your list I would add .NET’s XSD processor, which in your case will complain as:
The group ref to 'all' is not the root particle, or it is being used as an extension.With XSD 1.0 there is no solution that would give you what you want nicely and with a concised syntax unless you build a wrapper for e1 elements (below as e1s).
When it comes to e1 elements, they must be wrapped in e1s
or
Then it’ll all validate…