Implementing the xs:all tag
jenkins, run tests
hey, thanks for the patch!
one of your tests are failing, can you have a look?
What's the point of having a group name for the xs:all tag? What happens when you pass different values to xml_all_group ?
Will fix tests, pushed this out a bit late last night :)
I modeled the group name after the implementation of xs:choice, with the addition that xs:all is a direct subelement of complexType instead of in a sequence. I will add an additional failure case for when you specify two "all groups" in the same element
<xs:complexType name="AbcAll">
<xs:all>
<xs:element name="abc" type="xs:string"/>
<xs:element name="bcd" type="xs:string" minOccurs="0"/>
</xs:all>
<xs:all>
<xs:element name="cde" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
gets generated if I specify something like
class AbcAll(ComplexModel):
abc = Unicode(xml_all_group="all1", min_occurs=1)
bcd = Unicode(xml_all_group="all1")
cde = Unicode(xml_all_group="all2")
This then fails lxml schema validation in
Traceback (most recent call last):
File "/home/artanys/dev/dvenv/spyne/spyne/interface/xml_schema/_base.py", line 223, in build_validation_schema
self.validation_schema = etree.XMLSchema(etree.parse(f))
File "src/lxml/xmlschema.pxi", line 86, in lxml.etree.XMLSchema.__init__
I can add an explicit check for this in the code and throw a reasonable error
It's been some time since I looked at the xml schema spec so please correct me if I'm wrong here.
xsd:choice was implemented that way because there can be multiple choice tags. this is not the case for the xsd:all tag (is it?).
Instead of throwing an error, we have two options depending on whether you can have both <xsd:all> and <xsd:sequence> inside one complexType element.
If it's possible, we could change xml_all_group:str to xml_main_group:exactly_one_of('all', 'sequence') so you eliminate the source of the error in its root.
so your example becomes:
class AbcAll(ComplexModel):
abc = Unicode(xml_main_group='all', min_occurs=1)
bcd = Unicode(xml_main_group='all')
cde = Unicode(xml_main_group='sequence')
def = Unicode(xml_main_group='sequence')
which would generate:
<xs:complexType name="AbcAll">
<xs:all>
<xs:element name="abc" type="xs:string"/>
<xs:element name="bcd" type="xs:string" minOccurs="0"/>
</xs:all>
<xs:sequence>
<xs:element name="cde" type="xs:string" minOccurs="0"/>
<xs:element name="def" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
If having both all and sequence elements inside the complexType is not possible, then the main group should be implemented as a class attribute rather than an element attribute. So your example would become:
class AbcAll(ComplexModel):
class Attributes(ComplexModel.Attributes):
xml_main_group='all'
abc = Unicode(min_occurs=1)
bcd = Unicode
cde = Unicode
which would generate
<xs:complexType name="AbcAll">
<xs:all>
<xs:element name="abc" type="xs:string"/>
<xs:element name="bcd" type="xs:string" minOccurs="0"/>
<xs:element name="cde" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
It seems both could be implemented with minor modifications to your current patch.
So, what does the spec say?
Schema says they cannot coexist. Will look into making it a class attribute