-
-
Notifications
You must be signed in to change notification settings - Fork 39
Description
As was previously noted in #30 and #31, namespaces are being handled differently in each implementation. However, only two libraries behave consistently so there is no preferred way to handle namespaces. Also, it doesn't seem to be a bug in libxml, just a different default behaviour of each library. I have created this mini test for comparison: https://gist.github.com/jnv/11763399bcfcead72a2c
The source document contains namespaces both for elements and attributes.
Rexml drops namespaces for elements, but keeps attributes:
{"feed"=>
{"xmlns"=>"http://kosapi.feld.cvut.cz/schema/3",
"xmlns:atom"=>"http://www.w3.org/2005/Atom",
"xmlns:osearch"=>"http://a9.com/-/spec/opensearch/1.1/",
"xmlns:xlink"=>"http://www.w3.org/1999/xlink",
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
"xml:base"=>"https://kosapi.fit.cvut.cz/api/3",
"xml:lang"=>"cs",
"link"=>{"atom:rel"=>"next", "href"=>"courses?offset=10&limit=10"},
"startIndex"=>"0"}}Nokogiri and libxml behave the same, they drop namespaces both for elements and attributes:
{"feed"=>
{"link"=>{"rel"=>"next", "href"=>"courses?offset=10&limit=10"},
"startIndex"=>"0",
"base"=>"https://kosapi.fit.cvut.cz/api/3",
"lang"=>"cs"}}Ox keeps all namespaces:
{"atom:feed"=>
{"xmlns"=>"http://kosapi.feld.cvut.cz/schema/3",
"xmlns:atom"=>"http://www.w3.org/2005/Atom",
"xmlns:osearch"=>"http://a9.com/-/spec/opensearch/1.1/",
"xmlns:xlink"=>"http://www.w3.org/1999/xlink",
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
"xml:base"=>"https://kosapi.fit.cvut.cz/api/3",
"xml:lang"=>"cs",
"atom:link"=>
{"atom:rel"=>"next", "href"=>"courses?offset=10&limit=10"},
"osearch:startIndex"=>"0"}}Dropping all namespaces would be the easiest solution, however this may lead to name clashes, especially considering that attrattributes and elements are merged into the same hash.
Ox's behaviour seems most correct to me, though it copies names verbatim which may cause problems, for example <atom:rel atom:href="..."> and <atom:rel href="..."> results two different hash keys; same goes for Rexml.
Any ideas how this should be handled?
cc @flexik