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

Fixing documentation for XML::Node#namespace and added test for it with attribute nodes #803

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/nokogiri/xml_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ static VALUE attribute_nodes(VALUE self)
* call-seq:
* namespace()
*
* returns the default namespace set on this node (as with an "xmlns="
* attribute), as a Namespace object.
* returns the namespace of the element or attribute node as a Namespace
* object, or nil if there is no namespace for the element or attribute.
*/
static VALUE namespace(VALUE self)
{
Expand Down
18 changes: 15 additions & 3 deletions test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -977,16 +977,28 @@ def test_namespace
<y xmlns:c='http://bazz.com/'>
<a:div>hello a</a:div>
<b:div>hello b</b:div>
<c:div>hello c</c:div>
<div>hello moon</div>
<c:div x="1" b:y="2">hello c</c:div>
<div x="1" xmlns="http://ns.example.com/d"/>
<div x="1">hello moon</div>
</y>
</x>
EOF
set = xml.search("//y/*")
assert_equal "a", set[0].namespace.prefix
assert_equal 'http://foo.com/', set[0].namespace.href
assert_equal "b", set[1].namespace.prefix
assert_equal 'http://bar.com/', set[1].namespace.href
assert_equal "c", set[2].namespace.prefix
assert_equal nil, set[3].namespace
assert_equal 'http://bazz.com/', set[2].namespace.href
assert_equal nil, set[3].namespace.prefix # default namespace
assert_equal 'http://ns.example.com/d', set[3].namespace.href
assert_equal nil, set[4].namespace # no namespace

assert_equal 'b', set[2].attributes['y'].namespace.prefix
assert_equal 'http://bar.com/', set[2].attributes['y'].namespace.href
assert_equal nil, set[2].attributes['x'].namespace
assert_equal nil, set[3].attributes['x'].namespace
assert_equal nil, set[4].attributes['x'].namespace
end

if Nokogiri.uses_libxml?
Expand Down