Method: REXML::Element#namespace
- Defined in:
- lib/rexml/element.rb
#namespace(prefix = nil) ⇒ Object
:call-seq:
namespace(prefix = nil) -> string_uri or nil
Returns the string namespace URI for the element, possibly deriving from one of its ancestors.
xml_string = <<-EOT
<root>
<a xmlns='1' xmlns:y='2'>
<b/>
<c xmlns:z='3'/>
</a>
</root>
EOT
d = REXML::Document.new(xml_string)
b = d.elements['//b']
b.namespace # => "1"
b.namespace('y') # => "2"
b.namespace('nosuch') # => nil
619 620 621 622 623 624 625 626 627 628 |
# File 'lib/rexml/element.rb', line 619 def namespace(prefix=nil) if prefix.nil? prefix = prefix() end prefix = (prefix == '') ? 'xmlns' : prefix.delete_prefix("xmlns:") ns = namespaces[prefix] ns = '' if ns.nil? and prefix == 'xmlns' ns end |