Fix Schema::Element required? and array? methods#206
Conversation
In xml4r@133096b#diff-ff32e4dff2433e31f170b6f43842c940bec1c3581a07a5e3bc44887ce973fcc0L67-L76 the `min_occurs` and `max_occurs` getters were removed, saying they were "invalid". The additional message in [HISTORY](https://github.com/xml4r/libxml-ruby/blob/master/HISTORY#L63C111-L63C111) states: > Remove SchemaElement#minOccurs and SchemaElement#maxOccurs since they actually did not work (Charlie Savage) [Additional history here](https://github.com/search?q=repo%3Axml4r%2Flibxml-ruby+min_occurs&type=commits) I'm not aware of any more context surrounding the change, but those methods were still referenced by the Schema::Element's `array?` and `required?` methods. This PR adds tests for those two methods and adds simple ivar reader methods to replace those removed C methods.
|
Thanks for catching this and adding tests. The xml2 documentation says that minOccurs and maxOccurs are deprecated and not used. See https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/libxml2-schemasInternals.html So either we should remove the require method or figure out if there is an API to check this (I don't see one, but maybe there is). I don't think adding dummy ivars is the right approach since that will give back the wrong answer. |
That is unfortunate. AFAIK those are the only way to know the intended cardinality of an element. The commit that added those comments back in 2005 used to say The definition of the particle seems to be https://github.com/GNOME/libxml2/blob/d7cfe356500906fad0f3b3d186e1abbd5489a23c/xmlschemastypes.c#L355-L356 but I think that is private/internal? It's definitely not ideal to rely on a deprecated field, so maybe we can find a newer / future-proof way of obtaining the attribute values. Hopefully some of that history sparks an idea for you!
They do give back the correct answer. The tests should demonstrate this, and I am using a monkey-patched version in one of my production applications, hoping that this PR or something similar will be merged eventually. |
|
Great question, thanks for the prompt! ruby_xml_schema_type.c is using a reference to a Particle to set those ivars on Element. So it seems my first reading of the |
|
As for the one failing test on |
|
Yes, passed the second time. |
|
Thanks for fixing this. |
In this commit the
min_occursandmax_occursgetters were removed, saying they were "invalid". The additional message in HISTORY states:Additional history here
I'm not aware of any more context surrounding the change, but those methods were still referenced by the Schema::Element's
array?andrequired?methods. This PR adds tests for those two methods and adds simple ivar reader methods to replace those removed C methods.