Repository navigation
collect_namespaces: Different result since 1.5.6 #885
Description
Activity
See this real-world example with multiple default namespace declarations (Signer and Signature nodes).
Thanks for pointing this out. As mentioned in the relevant commit (c13f9a5) Nokogiri is relying on the underlying XML library to provide the namespaces.
In this case, it's unclear to me what the "right" behavior is, since the return value is (as you point out) a hash and both namespaces cannot be returned.
Rather than classifying this as a bug, I think the answer is that
#collect_namespacesshould return an array of tuples; but I'm not going to make that kind of a breaking change without bumping the major version, so maybe an alternative method? I'm open to discussion here.Yes, I don't see how you could touch
#collect_namespaceswithout breaking a lot of dishes. Only that what's been served on those dishes is not correct for all cases. My code naively depended on 1.5.5 behaviour and fell flat on its nose after c13f9a5. Lesson learned. Interesting, though, that the change didn't raise much, if any, concern.Can I suggest
#collect_all_namespaces(returns [[node,prefix,href], [...]]) without being flagellated to pieces?Using these in my code (dcp_inspect) now:
Nokogiri::XML::Document#collect_all_namespaces_href_keysandNokogiri::XML::Document#collect_all_namespaces_prefix_keys.@wolfgangw
#collect_all_namespacessounds fine to me. Could you draft this up?Sure, define draft up? Where and how?
@wolfgangw If you could make the changes you propose and submit a pull request, we can continue discussion over implementation there. This issue can be closed in favour.
- added a commit that references this issue
on Nov 13, 2013 I'm going to close this, as it's not clear how we can fix this without changing the return value of
collect_namespaces, which is sadly misdesigned given this edge case. I've captured this problem in the ROADMAP.md for future consideration.
Nokogiri::XML::Document#collect_namespaceswill return different results with version 1.5.5 and versions since 1.5.6 respectively.By the way: the sample below, while abstract and reduced, reflects real-world instance documents, not merely an academic exercise.
Consider this document with multiple default namespace scopes:
1.5.5:
1.5.6 and ever since:
This on ruby 2.0.0-p0. Reproducible with ruby 1.9.3-p194 / libxml 2.8.0.
Apart from the changed behaviour: Facing a document like the sample above (perfectly valid XML, I believe) a namespaces hash with attributes as keys won't fly, right? A list would. And break a million systems along the way. Essentially I'm looking for the proper mechanism to process these documents. Any hint appreciated.
By the way, the comment
Non-prefixed default namespaces (as in “xmlns=”) are not included in the hash.on Nokogiri's::XML::Document#collect_namespaces needs updating.