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 behavior between parsing and adding namespaces #943

Closed
rdingwell opened this issue Jul 20, 2013 · 4 comments
Closed

Inconsistent behavior between parsing and adding namespaces #943

rdingwell opened this issue Jul 20, 2013 · 4 comments

Comments

@rdingwell
Copy link

There is an inconsistency between what can be parsed as a namespace from a and what can be added via add_namespace.

This also appears as if this is more systemic to the fact that you cannot add a namespace to an element if the prefix you are trying to use already exists in the ancestry of the node you are trying to add it to.

doc = Nokogiri::XML('<a xmlns:a="x" ><b xmlns:b="y"/></a>')
b = doc.at("b")

b.add_namespace_definition("a","x")
b.namespace_definitions
=> [#(Namespace:0x3fcb3a703f88 { prefix = "b", href = "y" })]

b.add_namespace_definition("a","this:should:work")
b.namespace_definitions
=> [#(Namespace:0x3fcb3a703f88 { prefix = "b", href = "y" })]

While if it is parsed from a string/file/ect... this is not a problem. Either reusing the prefix with a new uri:

doc= Nokogiri::XML('<a xmlns:a="x" ><b xmlns:b="y" xmlns:a="this:should:work" /></a>')
b= doc.at("b")
b.namespace_definitions
=> [#(Namespace:0x3fcb3a58c0c4 { prefix = "b", href = "y" }),
#(Namespace:0x3fcb3a58c0b0 { prefix = "a", href = "this:should:work" })]

or by simply adding the same namespace mapping:

doc= Nokogiri::XML('<a xmlns:a="x" ><b xmlns:a="x" xmlns:b="y"/></a>')
b= doc.at("b")
b.namespace_definitions
=> [#(Namespace:0x3fcb3a6362e0 { prefix = "a", href = "x" }),
#(Namespace:0x3fcb3a6362cc { prefix = "b", href = "y" })]

Somewhat related to this is creating documents with builder where it will allow for reusing the prefix with a different uri but not if it is the same as a parents namespace.

doc = Nokogiri::XML::Builder.new { |xml|
      xml.a("xmlns:a" => "x") do
        xml.b("xmlns:a" => "x", "xmlns:b" => "y")
      end
    }.doc
b= doc.at("b")
=> [#(Namespace:0x3fcb3a6b3ba0 { prefix = "b", href = "y" })]

doc = Nokogiri::XML::Builder.new { |xml|
      xml.a("xmlns:a" => "x") do
        xml.b("xmlns:a" => "xs", "xmlns:b" => "y")
      end
    }.doc
 b= doc.at("b")
 => [#(Namespace:0x3fcb3a70890c { prefix = "a", href = "xs" }),
#(Namespace:0x3fcb3a708894 { prefix = "b", href = "y" })]

I discovered this while trying to fix some issues related to namespace and namespace caching in the Java implementation. Why cant namespaces be added if the prefix already exists in the hierarchy? It isn't a problem on parsing and redefining prefixes is perfectly legal in xml.

rdingwell added a commit to rdingwell/nokogiri that referenced this issue Aug 23, 2013
…parklemotion#940.  This allows for namespace prfixes to the redeclared at an element level, allows for default namespaces to be redeclared at an element level and fixes issues related to adding namepsaces delcarations on the document for use in xpath calls
rdingwell added a commit to rdingwell/nokogiri that referenced this issue Sep 27, 2013
…parklemotion#940.  This allows for namespace prfixes to the redeclared at an element level, allows for default namespaces to be redeclared at an element level and fixes issues related to adding namepsaces delcarations on the document for use in xpath calls
rdingwell added a commit to rdingwell/nokogiri that referenced this issue Oct 23, 2013
…parklemotion#940.  This allows for namespace prfixes to the redeclared at an element level, allows for default namespaces to be redeclared at an element level and fixes issues related to adding namepsaces delcarations on the document for use in xpath calls
@flavorjones
Copy link
Member

Will take a look.

@yokolet
Copy link
Member

yokolet commented Apr 15, 2014

This has been fixed by the commit 742751a
The test file in the pull request was added to the master, so the regress won't happen.

@yokolet yokolet closed this as completed Apr 15, 2014
@Confusion
Copy link

Will this fix be included in release 1.6.2? The issue is mentioned as fixed in the changelog for 1.6.2, but the fix was pushed 3 days ago, while the rc1 has been released 11 days ago. Will it make rc2 (will there even be an rc2?) and the upcoming release or could it be that it won't be included?

I ask this because it would help me get rid of quite a workaround I had in place to deal with it :).

@yokolet
Copy link
Member

yokolet commented Apr 19, 2014

It should be included in release 1.6.2. As the changelog says "1.6.2 / unreleased", it's not yet released. Since the fix is in master, version 1.6.2 should have this fix.

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

4 participants