When upgrading from libxml2 2.6 to 2.7, some behavior changed for me. I've located the bug report on their site that regards this change, its https://bugzilla.gnome.org/show_bug.cgi?id=571271 .
Interestingly, they report that "and I guess we misinterpreted the expected behaviour of this options (though I'm still not 100% sure)" - they weren't sure if they were reading the spec correctly yet they committed the fix.
I think the previous behavior is correct, so I wanted to see if anyone here has knowledge in either direction.
Basically, does <xs:all>elem1, elem2, ..<xs:all>
mean that "all or none of elem1, elem2.. must be present", or "any of elem1, elem2 .. may be present" ? Even though it seems like the former, two sources don't make this clear:
http://www.w3.org/TR/xmlschema-0/#ref18 - "All the elements in the group may appear once or not at all, and they may appear in any order."
http://www.w3schools.com/Schema/el_all.asp - "The example above indicates that the "firstname" and the "lastname" elements can appear in any order and each element CAN appear zero or one time!"
The script below, using lxml, reports success when using libxml2 2.6, but the second schema validation fails on 2.7. Can someone confirm if 2.7 is doing the right or the wrong thing here ?
from lxml import etree
from StringIO import StringIO
schema = """
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element type="parent-type" name="parent"/>
<xs:complexType name="parent-type">
<xs:all maxOccurs="1" minOccurs="0">
<xs:element type="xs:int" name="int-attr"/>
<xs:element type="xs:string" name="str-attr"/>
</xs:all>
</xs:complexType>
</xs:schema>
"""
xmlschema = etree.XMLSchema(etree.parse(StringIO(schema)))
# passes
doc1 = """
<parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
<str-attr>some value</str-attr>
<int-attr>12</int-attr>
</parent>
"""
# fails. it wants both "int-attr" and "str-attr" to be present.
# didn't think this was how "xs:all" worked ?
doc2 = """
<parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
<int-attr>12</int-attr>
</parent>
"""
for i, doc in enumerate((doc1, doc2, )):
doc = etree.parse(StringIO(doc))
try:
xmlschema.assertValid(doc)
print "document %d is valid." % i
except Exception, e:
print "document %d is not valid." % i
print e
output:
document 0 is valid.
document 1 is not valid.
Element 'parent': Missing child element(s). Expected is ( str-attr )., line 2