Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent namespaces handling #44

Open
jnv opened this issue Jul 2, 2014 · 0 comments
Open

Inconsistent namespaces handling #44

jnv opened this issue Jul 2, 2014 · 0 comments

Comments

@jnv
Copy link

jnv commented Jul 2, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant