GNOME Bugzilla – Bug 385372
xmllint only validates the last element in choice and produces warnings on "shared/choiced" fixed attributes
Last modified: 2021-07-05 13:27:23 UTC
Please describe the problem: With the the xml file (xmllint.xml) ==================8<================================================= <?xml version="1.0" encoding="utf8"?> <pet> <animal name="dog" type="dangerous"/> </pet> ==================8<================================================= and its xsd schema (xmllint.xsd) ==================8<================================================= <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="pet"> <xs:complexType> <xs:choice> <xs:element name="animal" type="cat"/> <xs:element name="animal" type="dog"/> <xs:element name="animal" type="hamster"/> <xs:element name="animal" type="lion"/> </xs:choice> </xs:complexType> </xs:element> <xs:complexType name="cat"> <xs:attribute name="name" use="required" fixed="cat"/> <xs:attribute name="type" use="optional" default="friendly"/> </xs:complexType> <xs:complexType name="hamster"> <xs:attribute name="name" use="required" fixed="hamster"/> <xs:attribute name="type" use="optional" default="friendly"/> </xs:complexType> <xs:complexType name="dog"> <xs:attribute name="name" use="required" fixed="dog"/> <xs:attribute name="type" use="optional" default="friendly"/> </xs:complexType> <xs:complexType name="lion"> <xs:attribute name="name" use="required" fixed="lion"/> <xs:attribute name="type" use="optional" default="dangerous"/> </xs:complexType> </xs:schema> ==================8<================================================= xmllint validation (2.6.17) failed and produces: on line 3 element animal: Element 'animal', attribute 'name': The value 'dog' does not match the fixed value constraint 'lion'. but if we choose lion, it works. This simple example reveals that only the last pet in the choice is checked. Steps to reproduce: To prove this again, if we change fixed="lion" to default="lion" (forcing to switch use to "optional") it works..and the funny part is...it works whatever you put in name of pet of the xml file..dangerous validation huh? Actual results: Expected results: I expect that : 1) it validates all the pets given (ie whose name is dog,cat,hamster or lion) not only lion. 2) in case I provide lion with name as default attribute (dangerous workaround), the other fixed values are checked (not ignored) 3) Each fixed attribute value on each element in choice that does not validates should do not produce warnings if one of the other element in the choice validates. Does this happen every time? Other information:
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.