Method: REXML::Attributes#namespaces
- Defined in:
- lib/rexml/element.rb
#namespaces ⇒ Object
:call-seq:
namespaces
Returns a hash of name/value pairs for the namespaces:
xml_string = '<a xmlns="foo" xmlns:x="bar" xmlns:y="twee" z="glorp"/>'
d = REXML::Document.new(xml_string)
d.root.attributes.namespaces # => {"xmlns"=>"foo", "x"=>"bar", "y"=>"twee"}
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 |
# File 'lib/rexml/element.rb', line 2426 def namespaces namespaces = {} each_attribute do |attribute| namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns' end doctype = @element.document&.doctype if doctype expn = @element. expn = doctype.name if expn.size == 0 doctype.attributes_of(expn).each { |attribute| namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns' } end namespaces end |